Hi everybody,
My question is: What is the difference between these two statements const char* p and char* const p ?
I appreciate your help,
Wesam
Printable View
Hi everybody,
My question is: What is the difference between these two statements const char* p and char* const p ?
I appreciate your help,
Wesam
const char* p
is a pointer to a constant char. The value that is pointed to can't be change.
char* const p
is a constant pointer to a char. The char can be change but it can't point to anything else.
Hope this helps...
Thank you, it helped; but may I ask another question in the same context: what is the advantage of declaring a pointer to a constant char for example where we can't change the value of that char and where we can set the pointer to point to different thing??
Wesam,
If you have a char* variable as a member of your class. You supply a const pointer, so that they can change the pointer, but are not allowed to change the string inside your class.
Thank you,
Wesam