Lets modify your program a little:
int main()
{
unsigned int a , b;
unsigned int *x, *y;
x = u8GetHeader();
y = u8GetHeader();
a = x[0];
b = y[1];
printf("The value of variable a = %d\n",a);
printf("The value of variable b = %d\n",b);
}
The first time the u8GetHeader
function is called it returns a pointer to the first element of the array. This gets assigned to the x
variable.
Each time after the first call, the u8GetHeader
function will return a pointer to the second element. This gets assigned to the y
variable.
Now if we "draw" the array and the pointers to the different elements in it it could look like this:
+---+---+---+---+
| 1 | 2 | 3 | 4 |
+---+---+---+---+
^ ^
| |
x y
It should be pretty clear that y
is pointing to the value 2
. That is y[0] == 2
. From this it should also be quite clear that adding 1
to that index (i.e. y[1]
) will then get the second element from y
, which is the value 3
. So y[1] == 3
.
Perhaps it is also useful to know that for any array of pointer p
and index i
, the expression p[i]
is exactly equal to *(p + i)
.
From this we get that y[1]
then must be *(y + 1)
., and if we add an arrow for y + 1
in the drawing we get:
+---+---+---+---+
| 1 | 2 | 3 | 4 |
+---+---+---+---+
^ ^ ^
| | |
x y y+1