3 ms·
The summary is "array and function has higher precedence than pointer, and parentheses override all". This explains why int *f(); is a function returning
by userbinator 5y ago
The summary is "array and function has higher precedence than pointer, and parentheses override all". This explains why
int *f();
is a function returning pointer to int, while
int (*f)()
is a pointer to function returning int. Likewise,
int *a[]
is an array of pointer to int, while
int (*a)[]
is a pointer to array of int.
- pmarreck 5y agobetween things like this and the pre- and post-increment/decrement operators, it's shocking that C code generates so many security holes ;)
- nicoburns 5y agoArgh! All of these examples seem backwards to me. Why on earth isn't "a pointer to an array of int" something like: *(int[])
- userbinator 5y agoBecause of how precedence works --- you start from the inside and work outwards, the same as when evaluating ordinary maths expressions. "Pointer to array of int" means you dereference it first to get an array of ints, then index to get an int.