Lets Take an example :
We have :
char *const p1="Shashwat";
char const* p2="Shriparv";
p2 is a pointer to a constant "Shriparv"
p2 can change to point to another constant string, but you can't change the value "Shriparv" thru p2.
p1 is a constant pointer to "Shashwat"
p1 can't change, but you can change "Shashwat" thru p1.
We have :
char *const p1="Shashwat";
char const* p2="Shriparv";
p2 is a pointer to a constant "Shriparv"
p2 can change to point to another constant string, but you can't change the value "Shriparv" thru p2.
p1 is a constant pointer to "Shashwat"
p1 can't change, but you can change "Shashwat" thru p1.
char const* p2 = "Shriparv";
*p2 = 'Somenew Shriparv Pointer'; // not allowed.
p2 = "New Shriparv"; // allowed
char * const p1 = "Shashwat";
*p1 = 'C'; // allowed
p1 = "New Shashwat"; // not allowed
No comments:
Post a Comment