3 ms·
`char * const a` is a different type from `const char *a`. In the first, the variable `a` is const, but `*a` is not const. That is, you cannot change the value
by moregrist 3y ago
`char * const a` is a different type from `const char *a`.
In the first, the variable `a` is const, but `*a` is not const. That is, you cannot change the value of `a` but you can change what it points to.
In the second `a` is not const, but `*a` is. That is, you can change `a` but you cannot change the value it points to.
I feel that your confusion is tied up in not understanding how C and C++ type declarations work, as is your insistence on `char* a`.
Dennis Ritchie (the C language designer) intended it to be written as `char *a` and talked about this at length over the years as an important design decision: variable declaration follows _usage_, so it’s `char *a` because the type of `*a` is `char`.
For better or worse, Stroustrup took this design decision into C++.
Sure both will parse in this simple case, but keeping this in mind is also the way that more complex declarations make sense.