I'm trying to deepen my understanding on syntax relevant to pointer in C, and I noticed that If I created an array of int first, int(*)[]
is a way of giving a pointer to this array, which seemingly could also be done by simply using int *
. So I'm confused what's the difference between pointer b and pointer c in Code below? If they're different, when should I use one way instead of choosing the other one?
#include <stdio.h>
int main(void)
{
int a[3];
int* b = a;
int (*c)[3] = &a;
printf("%p\n", a);
printf("%p\n", b);
printf("%p\n", c); //these 3 outputs are same.
}
I just tried to add lines of code to further understand this:
a[2] = 3;
printf("%i\n", a[2]); // = 3
printf("%i\n", b[2]); // = 3
It seems that b and c are different because printf("%i\n", c[2]) will generate an error. How to explain and understand all above?