...

/

Discussion: Superhero’s Secret Identity

Discussion: Superhero’s Secret Identity

Execute the code to understand the output and gain insights into array and pointer access.

Run the code

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

Press + to interact
#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 ...