Doesn't mention the standard "read it backwards to get the type", and consequently recommends "const int" over the superior "int const". int * const p; Is clearly a pointer to pointer to constant pointer to int. (Hint: read from right to left). This is made easier if you always put the const modifier to the right when it is optional. And just never, ever mix commas with pointer declarations.
How to interpret complex C/C++ declarations (2004)
11–14 of 14 posts
Re: How to interpret complex C/C++ declarations (2004)
#12Doesn't mention the standard "read it backwards to get the type", and consequently recommends "const int" over the superior "int const". int * const p; Is clearly a pointer to pointer to constant pointer to int. (Hint: read from right to left). This is made easier if you always put the const modifier to the right when it is optional. And just never, ever mix commas with pointer declarations.
Re: How to interpret complex C/C++ declarations (2004)
#13The main things to remember is that declaration mirrors use, and you don't actually directly declare the type of the variable, you declare the type of the expression that the declaration mirrors. // x has type int int x; // the expression *x has type int // -> x is something that, when dereferenced, yields an int // -> x is a pointer to int int *x; // x[n] has type int for some integer n // -> x is something, when ap…