Search⌘ K
AI Features

Discussion: Superhero’s Secret Identity

Learn to distinguish between array and pointer notation in C programming. Understand how pointers hold memory addresses and how to safely convert array indexing to pointer arithmetic. This lesson helps you grasp key memory concepts and avoid common errors in pointer usage.

Run the code

Now, it's time to execute the code and observe the output.

C
#include <stdio.h>
#define SIZE 5
int main()
{
int values[SIZE] = {2, 3, 5, 8, 13};
int *v, x;
/* initialize the pointer */
v = values;
for( x=0; x<SIZE; x++ ) {
printf("%2d = %2d\n",
values[x],
*(v+x)
);
}
return(0);
}

Understanding the output

The code uses both array and pointer notation to output the first five Fibonacci numbers:

2 = 2
3 = 3
5 = 5
8 = 8
13 = 13
Code output

Arrays and pointers

Arrays and pointers are similar but not exactly interchangeable. This relationship explains why many beginning C ...