100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Pointers and Arrays in C++

See how an array name decays into a pointer to its first element, and how `arr[i]` and `*(arr + i)` are two ways of writing the same thing.

PointersIntermediate7 min readJul 7, 2026
Analogies

1. Intro

Arrays and pointers are closely related in C++. In most expressions, an array name automatically "decays" into a pointer to its first element. This close relationship is why array elements can be accessed both with the familiar arr[i] syntax and with pointer notation *(arr + i) — they compile to the same thing.

🏏

Cricket analogy: A scoreboard listing overs by number (arr[i]) is really the same as pointing at the start of the innings and counting forward i overs (*(arr + i)) — both land on the same over, like referencing Rohit Sharma's fourth over two different ways.

2. Syntax

cpp
int arr[5] = {1, 2, 3, 4, 5};
int* p = arr;        // same as: int* p = &arr[0];
arr[i];                // subscript notation
*(arr + i);            // equivalent pointer notation
*(p + i);              // also equivalent, via p

3. Explanation

When an array arr is used in most expressions (as a function argument, assigned to a pointer, used in arithmetic), it decays into a pointer to its first element: arr behaves the same as &arr[0]. This is why int* p = arr; compiles without needing &arr[0] explicitly. Because of this decay, indexing an array with arr[i] is defined in the language as shorthand for *(arr + i) — first move the pointer i elements forward using pointer arithmetic, then dereference it. Both forms give identical results and even allow the unusual-looking but valid i[arr], since addition is commutative. One key difference: unlike a real pointer, the array name itself is not a modifiable variable — you cannot reassign arr to point elsewhere, though a pointer copy of it (p) can be reassigned freely.

🏏

Cricket analogy: A commentator saying "the sixth over" (arr[5]) means the same as "start at the first over and count five more" (*(arr + 5)); the innings itself can't be reassigned to start elsewhere, but a bookmark copy of it can be moved freely.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    int arr[5] = {10, 20, 30, 40, 50};
    int* p = arr;    // array decays to pointer to arr[0]

    for (int i = 0; i < 5; i++) {
        cout << "arr[" << i << "] = " << arr[i]
             << " | *(arr+" << i << ") = " << *(arr + i)
             << " | *(p+" << i << ") = " << *(p + i) << endl;
    }

    cout << "arr == &arr[0]? " << (arr == &arr[0]) << endl;

    return 0;
}

5. Output

text
arr[0] = 10 | *(arr+0) = 10 | *(p+0) = 10
arr[1] = 20 | *(arr+1) = 20 | *(p+1) = 20
arr[2] = 30 | *(arr+2) = 30 | *(p+2) = 30
arr[3] = 40 | *(arr+3) = 40 | *(p+3) = 40
arr[4] = 50 | *(arr+4) = 50 | *(p+4) = 50
arr == &arr[0]? 1

6. Key Takeaways

  • An array name decays to a pointer to its first element in most expressions, so arr behaves like &arr[0].
  • arr[i] is defined as shorthand for *(arr + i); both notations are interchangeable.
  • Pointer arithmetic scaling (from sizeof the element type) is what makes arr + i land on the correct element.
  • Unlike a pointer variable, the array name itself cannot be reassigned to point elsewhere.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#PointersAndArraysInC#Pointers#Arrays#Syntax#Explanation#DataStructures#StudyNotes#SkillVeris