I have recently started to learn ANSI C. I have come across this:
int a[7];
*(a+2);
I don't understand how it's possible to add 2 to a. Does it add 2 to every element in a?
Also, what is the function of the *? Does it create a pointer?
I have recently started to learn ANSI C. I have come across this:
int a[7];
*(a+2);
I don't understand how it's possible to add 2 to a. Does it add 2 to every element in a?
Also, what is the function of the *? Does it create a pointer?
a+2 causes a to be interpreted as a pointer to a's first element. This is called array decaying.
It then offsets that pointer by 2 and dereferences (*) the resulting pointer. So it's the same as a[2].