Array decay to pointers, and address of operator (dereference) behavior.

Last update: 05 January, 2026

Address of operator

The address of operator (&) creates a pointer of the underlying type. For example:

int number = 5;
auto what = &number;
// "what" is an `int *`, a pointer to the underlying int

auto what = number
// "what" is an `int`

Array decay to pointer

int numbers[10] = { 0 };
auto what = numbers
// "what" is not an int[10] because array decay to pointers
// when evaluated in an expression. So "what" decays
// from `int[10]` to `int *`
auto what = &numbers;
// "what" is `int (*)[10]`, a pointer to an array of 10
// ints. Here, the address of operator prevents the decay
// and creates a pointer to the underlying type, which is
// an array of 10 ints.
auto what = numbers[1];
// "what" is an int

Multi-dimensional array

int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} };
auto what = matrix;
// matrix is an array that holds 2 arrays that, in turn,
// hold 3 ints. When you have an array, of any type, in an
// expression, that array decays to a pointer.
// So, "what" is now `int (*) [3]` a pointer to an array of 3 ints.
// Goodbye to the array of 2, now it's a pointer.

auto what = &matrix;
// This time, the address-of operator prevents the decay
// and "what" is a pointer to the original type, which
// is int[2][3], or an array that holds 2 arrays that hold 3 ints.
// So, technically, "what" is an `int (*) [2][3]`.

auto what = matrix[0];
// matrix [0] is an int[3] array and we know that array
// decay to pointers in expressions.
// So, "what" is an `int *` here.

auto what = &matrix[0];
// Again, matrix[0] is of type `int[3]`. The address-of
// operator prevents the decay of the `int[3]` to `int *`
// and, in addition,  it gives us a pointer to the `int [3]`.
// So, "what" is of type `int (*) [3]`, Or a pointer to an
// array of 3 ints.

auto what = matrix[0][0];
// "what" is `int` here.

auto what = &matrix[0][0];
// `matrix[0][0]` is an int, so `&matrix[0][0]` is a
// pointer to int (`int *`).

decltype

Btw, in C++, expressions in decltype don’t decay the same way arrays decay to pointers in expressions

int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} };
using what = decltype(matrix);
// "what" is a reference to an `int matrix[2][3]`, or a
// `int (&) [2][3]`.

using what = decltype(matrix[0]);
// what is a `int (&) [3]`

using what = decltype(matrix[0][0]);
// what is a `int &`

int number = 5;
using what = decltype(number);
// what is `int`. Don't ask me why it's different from the
// above.

Something to run to observe the above:

int main()
{
    int matrix[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
    int* pi = matrix[0];
    int** ppi = π
    int number = 7;
    std::cout << "           pi: " << pi << '\n';
    std::cout << "          *pi: " << *pi << '\n';
    std::cout << "          &pi: " << &pi << '\n';
    std::cout << "       pi + 1: " << pi + 1 << '\n';
    std::cout << "    *(pi + 1): " << *(pi + 1) << '\n';

    std::cout << "          ppi: " << ppi << '\n';
    std::cout << "         *ppi: " << *ppi << '\n';
    std::cout << "         &ppi: " << &ppi << '\n';
    std::cout << "      ppi + 1: " << ppi + 1 << '\n';
    std::cout << "   *(ppi + 1): " << *(ppi + 1) << '\n';

    std::cout << "       number: " << number << '\n';
    std::cout << "      &number: " << &number << '\n';

    std::cout << "       matrix: " << matrix << '\n';
    std::cout << "      &matrix: " << &matrix << '\n';
    std::cout << "   &matrix[0]: " << &matrix[0] << '\n';
    std::cout << "&matrix[0][0]: " << &matrix[0][0] << '\n';
    std::cout << "&matrix[0][1]: " << &matrix[0][1] << '\n';
    std::cout << "&matrix[0][2]: " << &matrix[0][2] << '\n';
    std::cout << "   &matrix[1]: " << &matrix[1] << '\n';
    std::cout << "&matrix[1][0]: " << &matrix[1][0] << '\n';
    std::cout << "&matrix[1][1]: " << &matrix[1][1] << '\n';
    std::cout << "&matrix[1][2]: " << &matrix[1][2] << '\n';
    return 0;
}

The naming of the what variable was probably poor, I had to enclose it in parentheses to make it clear I was referring to the variable. I always thought of “So What” by Anti-Nowhere League/Metallica.

Other things to read

Popular

Previous/Next