pointer

M

MJ

hi
what is the difference between the following
const char * p ; // data is constant // Line 1
char * const p ; // pointer is constant // Line 2

but I have doubt in the following statement
char const *p ; // Line 3

As per my understanding the statement in line 1 and line 3 are same....
Please let me know if I am wrong ...

MJ
 
V

Victor Bazarov

MJ said:
what is the difference between the following
const char * p ; // data is constant // Line 1
char * const p ; // pointer is constant // Line 2

The difference is stated in the comments. Read it carefully.
but I have doubt in the following statement
char const *p ; // Line 3

As per my understanding the statement in line 1 and line 3 are same....

Yes, that's correct.

V
 
R

Rolf Magnus

MJ said:
hi
what is the difference between the following
const char * p ; // data is constant // Line 1
char * const p ; // pointer is constant // Line 2

but I have doubt in the following statement
char const *p ; // Line 3

As per my understanding the statement in line 1 and line 3 are same....
Please let me know if I am wrong ...

You are not wrong. const always binds to the left side, except when there is
nothing on the left side (like in line 1). In that case, it binds to the
right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top