const int *const p can be writted as int const *const p?

Yes or no? Thanks.
Simple answer: no

Reason: p has no type


misread the title.

new answer: yes
http://stackoverflow.com/questions/1143262/what-is-the-difference-between-const-int-const-int-const-int-const
Last edited on
Thanks! But still confused!

const int * const p can be written as int const *const p, so that means const can switch position with the type, then

can we write int * const p as int const* p? and then written as const int *p, and then that is obviously wrong.

Do you understand what I mean?
Last edited on
I mean int and * are all types, now that const can be any side of int then it maybe any side of *
read it backwards. Like to answer in the stackoverflow link.

1 - int * const p is read as: p is a constant pointer to integer.
2 - int const* p is read as: p is a pointer to constant integer.
3 - const int *p is read as: p is a pointer to integer constant.

replace: const with "constant", * with "pointer to", and int with "integer"

1, 2, 3: p is a pointer.
1: p cannot change its value (the address it points to) since it is a constant pointer (or pointer constant).
2, 3: p can change its value (it can point to another addresses).

So 1 is not equivalent to 2... but 2 and 3 are the same.
Last edited on
Thanks!
Topic archived. No new replies allowed.