1. Common Declarations#
int a: Declaresaas an integer variable.int const a: Declares a constant integera(cannot be modified).int *a: Can be understood as “*ais an integer”, soais a pointer to an integer.int **a: Since “**ais an integer”,ais a pointer to a pointer to an integer.
Note:
int *a, b;declaresaas a pointer to an integer, butbis just an integer—not a pointer.
int const *p:pis a pointer to a constant integer (the value pointed to cannot be modified).int *const p: Declarespas a constant pointer to an integer (the pointer itself cannot change, but the value pointed to can be modified).
2. Combined with Function Declarations#
int f(): Declares a functionfthat returns an integer. (This is the old-style declaration without parameter types.)int *f(): Sincef()has higher precedence, this declaresfas a function returning a pointer to an integer.int (*f)():*fbinds first, meaningfis a pointer to a function that returns an integer.int *(*f)(): Declaresfas a pointer to a function that returns a pointer to an integer.
3. Combined with Arrays#
int a[]: Declares an array of integers.int *a[]: Since the subscript operator[]has higher precedence, this declaresaas an array of pointers to integers.int (*a[])():ais an array of function pointers, where each pointer points to a function returning an integer.