Skip to main content
A pointer parameter in C is a function argument that accepts a memory address rather than a direct data value. By passing a pointer, the function receives a reference to the original variable’s location in memory, enabling direct manipulation of the caller’s data and avoiding the overhead of copying large data structures. Under the hood, C strictly employs pass-by-value semantics. When a pointer is passed as a parameter, the function receives a local, independent copy of the memory address. Modifying the pointer variable itself within the function does not affect the original pointer in the calling scope. However, applying the indirection operator (*) to the pointer allows the function to mutate the data residing at that specific memory address.

Memory Model Behavior

When a function with a pointer parameter is invoked:
  1. A new stack frame is allocated for the called function.
  2. The pointer parameter (e.g., ptr) is instantiated as a local variable within this new stack frame.
  3. The value assigned to ptr is the raw memory address of the argument passed by the caller.
  4. Any dereference operation (*ptr) resolves this address, crossing stack frame boundaries to read or write to the caller’s original memory location.

Const Qualifiers in Pointer Parameters

Pointer parameters frequently utilize the const qualifier to enforce strict memory access controls at compile-time. The placement of the const keyword relative to the asterisk (*) dictates the mutability of the pointer and the underlying data.

Array Decay

In C function signatures, array parameters automatically decay into pointers to their first element. The compiler treats an array declaration in a parameter list as syntactically and semantically identical to a pointer declaration. Because of this decay, the sizeof operator applied to an array parameter will yield the size of the pointer, not the size of the original array.
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More