✨Organizing C Pointer Declarations

1. Common Declarations Link to heading

  • int a: Declares a as an integer variable.

  • int const a: Declares a constant integer a (cannot be modified).

  • int *a: Can be understood as “*a is an integer”, so a is a pointer to an integer.

  • int **a: Since “**a is an integer”, a is a pointer to a pointer to an integer.

Note: int *a, b; declares a as a pointer to an integer, but b is just an integer—not a pointer.

  • int const *p: p is a pointer to a constant integer (the value pointed to cannot be modified).

  • int *const p: Declares p as a constant pointer to an integer (the pointer itself cannot change, but the value pointed to can be modified).

2. Combined with Function Declarations Link to heading

  • int f(): Declares a function f that returns an integer. (This is the old-style declaration without parameter types.)

  • int *f(): Since f() has higher precedence, this declares f as a function returning a pointer to an integer.

  • int (*f)(): *f binds first, meaning f is a pointer to a function that returns an integer.

  • int *(*f)(): Declares f as a pointer to a function that returns a pointer to an integer.

3. Combined with Arrays Link to heading

  • int a[]: Declares an array of integers.

  • int *a[]: Since the subscript operator [] has higher precedence, this declares a as an array of pointers to integers.

  • int (*a[])(): a is an array of function pointers, where each pointer points to a function returning an integer.