Explain the difference between const int * and int const *.
Anonymous
The answer above is inaccurate. 1) const int * a1; 2) int const * a2; 3) int * const a3; 1 and 2 are the same ('const' keyword before the '*'): creates a pointer whose pointed data is constant, but the pointer value which contains the address itself is not constant. Yet 3 creates a pointer which is constant, but the values pointed to are variable. So: *a1 = 5; // error C2166: l-value specifies const object *a2 = 5; // error C2166: l-value specifies const object a2++; // works fine, pointer itself is not const and can be changed. a3++; // error C2166: l-value specifies const object *a3 = 5; // works fine, pointed value is not const and can be changed.
Check out your Company Bowl for anonymous work chats.