What is the difference between the following declarations?
const char *s;
char const *s;
Please mention it briefly.
NOTE : [I][This question was asked by Dhananjaya Mohanty[/I][I]][/I]
Printable View
What is the difference between the following declarations?
const char *s;
char const *s;
Please mention it briefly.
NOTE : [I][This question was asked by Dhananjaya Mohanty[/I][I]][/I]
const char *s;
This declares a constant data and a variable pointer.
char const *s;
This is invalid i think. I should look like:
char * const s;
This declares a variable data and a constant pointer.
const char * const s;
This declares a constant data and constant pointer.
The two declarations namely
const char *s;
and
char const *s;
are not equivalent.
In the first statement namely
const char *s;
the char is constant.
But in the second statement namely
char const *s;
the pointer itself is const. So in this it is not possible to change the pointer using any of the
pointer arithmetic say as s++.
char const *s;
the pointer itself is const. So in this it is not possible to change the pointer using any of the
pointer arithmetic say as s++.
Barbie and Admin, Thanks for your answers
nitin.pathak Thanks for you also, your answer is same as last part of admin answer
Very interesting question and answer on pointer concepts. Friends thanks for such useful posts.