-
Moderator
Difference between following declarations
What is the difference between the following declarations?
const char *s;
char const *s;
Please mention it briefly.
NOTE : [This question was asked by Dhananjaya Mohanty]
-
Expert Member
Re: Difference between following declarations
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.
-
Administrator
Re: Difference between following declarations
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++.
-
Junior Member
Re: Difference between following declarations
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++.
-
Moderator
Re: Difference between following declarations
Barbie and Admin, Thanks for your answers
nitin.pathak Thanks for you also, your answer is same as last part of admin answer
-
Contributing Member
Re: Difference between following declarations
Very interesting question and answer on pointer concepts. Friends thanks for such useful posts.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules