can you please explain me What is the difference between const * char and const char * ?
they both are same.
Difference between const char* p and char const* p?
In const char* p, the character pointed by ‘p’ is constant, so u cant change the value of character pointed by p but u can make ‘p’ refer to some other location. in char const* p,
the ptr ‘p’ is constant not the character referenced by it, so u cant make ‘p’ to reference to any other location but u can change the value of the char pointed by ‘p’.
I am sure you will get your answer along with example at below location
const char *p and char *const p both look similar, but are different!
const char *p -- It is a non constant pointer to constant data. That means the data to which it is pointing can never be changed. For example, char mychar = 'a'; const char *p = & mychar; *p = 'b'; //not possible as value at ptr is constant i.e. 'a' char *const p -- It is a constant pointer to non constant data. That means, this pointer points to address that is constant and thus pointer cannot point to other address. For example, char mychar = 'a'; char mychar2 = 'z'; const char *p = &mychar; *p = 'b'; //possible as value at ptr is constant i.e. 'a' p = &mychar2; //not possible as you cannot change address value of pointer