int *const p[];
// ( ^ )----Read this like a statement.
// ^----------------The returned value is of type int.[/code]
If you index p as an array you get a value, which if dereferenced as a constant pointer will return an int.
This is how it is implemented. If we wanted to group the pointer and array declaration with the type, there would be a much more natural way: (const* int)[] p; //p is an array of constant pointers to int
But someone decided that we do it the other way and we have for the last 30 years. Writing int* p only leads to confusion because it really means int(* p).
Also, type declaration semantics in C are completely retarded. If it were up to me, they would be interpreted right-to-left, simple and straightforward. Like so: int volatile *const [] * (int, int) * a; // 'a' is a pointer to a function(int, int) returning a pointer to an array of const pointers to volatile int
Name:
Anonymous2013-07-21 13:26
I mean seriously, what the fuck is this shit? volatile int *const(*(*a)(int, int))[]
They should put that in the newspaper next to the crosswords and sudokus. "Decipher the type declaration".
Just why, I ask.
int is a type. float is a type. double is a type. int* is NOT a type.
For example: int a, b; // declares two ints
float c, d; // declares two floats
double e, f; // declares two doubles
int* g, h; // DOESN'T declare two pointers to ints, but a pointer to an int and an int
The compiler applies * to the variable, not the type. Therefore, you should associate * with the variable, not the type, just as you would when you're dereferencing the pointer (*p) or incrementing it (p++) or decrementing it (p--).
Surely, you wouldn't write expressions like the int x =* p; or int y =++ x;. int* p is just as retarded.