A pointer to an array is a distinct derived data type in C that stores the memory address of an entire array, rather than pointing to a single element. It encapsulates both the base data type and the dimension of the array within its type signature. While typically associated with arrays of fixed compile-time sizes, C99 introduced Variable Length Arrays (VLAs), allowing pointers to arrays where the dimension is evaluated at runtime.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax and Declaration
Because the array subscript operator[] has higher precedence than the dereference operator *, parentheses are mandatory when declaring a pointer to an array.
Initialization and Type Compatibility
When an array identifier is used in an expression, it typically decays into a pointer to its first element. However, when the address-of operator (&) is applied to an array identifier, it yields the address of the entire array.
arr and &arr evaluate to the same memory address at runtime, their compile-time types and behaviors are fundamentally different:
arrhas the compile-time typeint[5]. In most expressions (with notable exceptions likesizeof(arr)and&arr), it decays into a pointer to its first element, yielding the typeint *.&arrapplies the address-of operator directly to the array type, yielding a pointer to the entire array. Its type isint (*)[5].
Pointer Arithmetic
Pointer arithmetic is dictated by the size of the type being pointed to. Incrementing a pointer to an array advances the memory address by the total byte size of the entire array, not a single element.Dereferencing and Element Access
To access individual elements through a pointer to an array, you must first dereference the pointer to yield the array itself. Due to operator precedence, the dereference must be enclosed in parentheses before applying the subscript operator.Relationship to Multi-Dimensional Arrays
In C’s type system, a 2D array is an array of 1D arrays. When a 2D array identifier decays, it becomes a pointer to its first element—which is a 1D array. Therefore, a pointer to an array is the exact type yielded by the decay of a 2D array.Function Parameters and Array Adjustment
The most critical application of pointers to arrays is passing multi-dimensional arrays to functions. When an array of arrays is declared as a function parameter, C automatically adjusts the parameter type to be a pointer to an array.int matrix[3][5] decays into a pointer to its first element (int (*)[5]) when passed as an argument, the receiving function must accept a pointer to an array of the correct inner dimension. This ensures that pointer arithmetic within the function correctly skips over entire rows (e.g., matrix[1] advances the pointer by 5 * sizeof(int) bytes).
Master C with Deep Grasping Methodology!Learn More





