answersLogoWhite

0

What Difference between const char p and char const p?

Updated: 9/17/2019
User Avatar

Wiki User

9y ago

Want this question answered?

Be notified when an answer is posted

Add your answer:

Earn +20 pts
Q: What Difference between const char p and char const p?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Difference between const char and char const?

const char *p means the char value pointed by 'p' is constant we can't change anyway but the address(location) of 'p' can change. char const *p means the char value pointed by 'p' can change but the location of p can't be change it is constant.


Program to implement strdup in C?

char *strdup (const char *s) { size_t len; char *p; if ( !s ) return NULL; len = strlen (s); p = malloc (len+1); if (p && len) { memcpy (p, s, len); p[len] = '\0'; } return p; }


Difference between char pointer and char buffer?

The difference here is that char *p = "Hello"; will place Hello world in the read-only parts of the memory and making p a pointer to that, making any writing operation on this memory illegal. While doing: char p[] = "Hello"; puts the literal string in read-only memory and copies the string to newly allocated memory on the stack. p[0] = 'A'; is legal.


Write the character counting function using pointers in C programming?

What characters do you want to count? As I am not a mind-reader, I can only give you an example which might give you an idea. size_t count_specified_char_occurances (const char *s, int c) { const char *p= s-1; size_t count= 0; while (*++p) if (*p==(char)c) ++count; return count; } int main (void) { printf ("P in APPLE: %d\n", (int)count_specified_char_occurances ("APPLE", 'P'); return 0; }


How would you write a program that counts the number of lowercase in a character?

I would use a loop like this: const char *p= str-1; size_t count= 0; while (*++p) if (islower (*p)) ++count;


C program code for concatenation of string?

Here You Are : void String_Concate(char *Arr1, char *Arr2) { int r=0; int c = String_Length(Arr1); int x,p; for(int i=0;Arr1[i];i++) { if((Arr1[i]== 32)(Arr1[i]=='\0')) {r= i; break;} } for(x = r,p =0;x<=c + String_Length(Arr2);x++,p++) { *(Arr1 + x) = *(Arr2 + p); } } Have A nice Day


How do you write a program to find the length of a string?

/* with run-time library */ int len; char* str; len = strlen (str); /* without run-time library */ int mystrlen (const char* str) { int len; while (*str != '\0') { len++; str++; } return len; } int len; char* str; len = mystrlen(str);


Code in c plus plus of phonebook using linked list?

#include<iostream> #include<list> class person { std::string m_name; std:string m_phone; public: const char* get_name()const{return( name.c_str() );} const char* get_phone()const{return( phone.c_str() );} person(std::string m_name, std::string m_phone) : m_name(name), m_phone(phone) {} }; int main() { std::list<entry*> phonebook; person* p = new entry("Joe Bloggs","01234 555 6789"); phonebook.push_back(p); p = new person("Ann Other", "01234 555 9876"); phonebook.push_back(p); p = new person("Some One", "01234 555 8769"); // and so on... return(0); }


How would you read int const p?

int const *p declares a 'p' pointer, that points to a constant integer


What are used raw materials in baking industries?

/*------------------------------------------------------------------------ Section :G/7 M/c No.:32, Roll No.:11BT30015 Name :M A KRISHNA DEEPAK Assignment No.: 08 Description: Program to implement functions on string characters. ------------------------------------------------------------------------*/ #include <stdio.h> #define MAXLEN (1000+1) int strLength(const char *x); void strReverse(char *x); int makeUpper(char *x); char *strCopy(char *x, const char *y); int isPrefix(const char *x, const char *y); char *substring(char *x, const char *y); int main() { int len ; char x[MAXLEN], y[MAXLEN], z[MAXLEN], *cP; printf("Enter the 1st string:\n") ; scanf("%[^\n]", x) ; printf("Enter the 2nd string:\n") ; scanf(" %[^\n]", y) ; printf("Length("%s") = %d\n", x, len = strLength(x)); printf("Reverse("%s") = ", x); strReverse(x) ; printf(""%s"\n", x); strReverse(x) ; makeUpper(x); printf("Upper-case: "%s"\n", x); if(isPrefix(x, y)) printf(""%s" is a prefix of "%s"\n", y, x) ; else printf(""%s" is not a prefix of "%s"\n", y, x) ; /*if((cP = substring(x, y)) == NULL) printf(""%s" is not a substring of "%s"\n", y, x) ; else { printf(""%s" is a substring of "%s"", y, x) ; printf(" from index %d\n", (int)(cP-x)) ; } */ printf("z[] = "%s"\n", strCopy(z,x)) ; return 0; } int strLength(const char *x) { static int sum=0; int temp; if(*x=='\0') { temp=sum; sum=0; return temp; } else { sum++; return strLength(x=x+1); } } void strReverse(char *x) { int length,c; char *begin,*end,temp; length=strLength(x); begin=x; end=x; for(c=0;c<(length-1);c++) end++; for(c=0;c<length/2;c++) { temp=*end; *end=*begin; *begin=temp; begin++; end--; } } int makeUpper(char *x) { static int u=0; int temp; if(*x=='\0') { temp=u; u=0; return temp; } else { if(*x>='a' && *x<='z') { *x-=32; u++; } return makeUpper(x=x+1); } } char *strCopy(char *x, const char *y) { char *p=x; while(*y) { *x =*y; y++; x++; } *x ='\0'; return p; } int isPrefix(const char *x, const char *y) { static int l=strLength(y),p=0; if(*y!=*x *y!='\0') return 0; if(*y==*x) { p+=isPrefix(x=x+1,y=y+1); } if(i==strLength(y)) return 1; } /*char *substring(char *x, const char *y) { } */


C plus plus programs - to replace every space in a string with a hyphen?

char *string = "this is a test"; char *p; for (p=string; *p!='\0'; p++) if (*p==' ') *p='-';


When should not type cast used?

Example for pointless typecast: char *p, *q; p= (char *)q;