How to Substitute Pointers for Array Notation in C Programming - dummies

How to Substitute Pointers for Array Notation in C Programming

By Dan Gookin

Arrays in the C programming language are nothing but a kettle full of lies! Truly, they don’t exist. As you discover the power of the pointer, you come to accept that an array is merely a cleverly disguised pointer. Be prepared to feel betrayed.

Array notation is truly a myth because it can easily be replaced by pointer notation. In fact, internally to your programs, it probably is.

Assume that pointer a is initialized to array alpha. The array and pointer must be the same variable type, but the notation doesn’t differ between variable types. A char array and an int array would use the same references.

Array alpha[] Pointer a
alpha[0] *a
alpha[1] *(a+1)
alpha[2] *(a+2)
alpha[3] *(a+3)
alpha[n] *(a+n)
You can test your knowledge of array-to-pointer notation by
using a sample program, such as the one shown in A Simple Array


#include <stdio.h>
int main()
 float temps[5] = { 58.7, 62.8, 65.0, 63.3, 63.2 };
 printf("The temperature on Tuesday will be %.1fn",
 printf("The temperature on Friday will be %.1fn",

Exercise 1: Modify the two printf() statements from A Simple Array Program, replacing them with pointer notation.