c++11 - C++: Confusion on auto deduction using a const against an array -


example code:

int aa[] = {1,2,3,4}; auto const p = aa; 

why p deduced int *const instead int const *?

because aa non-const array, decay pointer-to-non-const , therefore p deduced pointer-to-non-const. , because declared p const, const pointer-to-non-const.

declaring variable const make variable const. doesn't make type of variable different (pointer-to-const , pointer-to-non-const different types) except in sense may const qualified version of same type.


Comments