3 ms·
The 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 expre
by Sharlin 13y ago
The 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 applied the array subscript operator to, yields an int
// -> x is an array of ints
int x[5];
// x() has type int
// -> x is something that, when called, returns int
// -> x is a function returning int
int x();
// *x() has type int
// -> by operator precedence, calling x, then applying *, yields an int
// -> x is a function returning a pointer to int
int *x();
// (*x)() has type int
// -> dereferencing x, then calling the result, yields an int
// -> x is a pointer to a function returning int.
int (*x)();
- ygra 13y agoI've never noticed this before. Honestly, this makes things a lot clearer. And while it's still not terribly easy to figure out things like char ((x())[5])() it makes a lot more sense.