Question:
What's the difference between const char *p, char const *p, and char * const p?
PC
2007-04-18 23:06:44 UTC
What's the difference between const char *p, char const *p, and char * const p?
...
Please give me an example .. I found some answers but not so explainatory
Five answers:
cute nisha
2007-04-18 23:14:54 UTC
1. const char *p : means p is pointer pointing to a constant char i.e. you can not change the content of the location where it is pointing but u can change the pointer itself to point to some other char.



2. char const *p, and char * const p : both are same & in this case p is a constant pointer poiting to some char location. you can change the contents of that location but u can't change the pointer to point to some other location.



hope i answered the way u wanted !!
2016-12-08 22:30:06 UTC
Char Const Vs Const Char
viss
2015-04-01 22:11:29 UTC
First two const char *p and char const *p both are same i.e. points to constant character(You can change where p points, but you can’t change pointed characters using that pointer).



But char * const p is a constant pointer to a variable(i.e. you can’t change the pointer).
?
2016-04-01 12:16:18 UTC
char const *p; is legal way to declare
sarvesh k
2007-04-19 00:41:23 UTC
hi...

const char *p:- the variable in the address is constant. u can not re-define.



char const *p : the value can be changed, u can not re-allocate the memory.

char * const p: same as previous.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...