Skip to main content

Pointers and Arrays in C

In C, the name of an array is a pointer to its first element. This tight relationship means you can traverse and manipulate arrays entirely through pointer arithmetic.

Accessing Array Elements via Pointer

*(ptr + i) and num[i] are completely equivalent — the compiler translates num[i] to *(num + i) internally.

Array of Pointers

An array where each element is a pointer:

Example 1: Array of Integer Pointers

Output:

Example 2: Array of String Pointers

Useful for storing a list of strings without a 2D character array:
Output:

arr[i] vs *(arr + i)

These two are identical in C:

Key Points

  • arr (array name) decays to &arr[0] when used in an expression
  • sizeof(arr) gives the total array size; sizeof(ptr) gives only the pointer size
  • You can increment a pointer (ptr++) but not an array name (arr++ is illegal)