Skip to main content

Section 19.11 Arrays and Pointers

Given an array variable such as int myArray[6]; what exactly does the variable myArray itself store (if we don’t add in the brackets to refer to a specific element)? It turns out, myArray holds the address of the zeroth element of the array! That is, myArray is a pointer of type int. So:
myArray == &myArray[0]
But it gets even better than that: The computer can do arithmetic, giving us the ability to easily find the address of myArray[1] or myArray[2], for example:
myArray + 1 == &myArray[1]
myArray + 2 == &myArray[2]
This is called pointer arithmetic. So by adding 1 to the address myArray, the computer automatically locates the address of the next array element, &myArray[1].
Watch the video to find out more.

If you cannot see this codecast, please click here.

Aside: Video Description.