Although I've learned and worked with many advanced languages, but today when I was refreshing my C skills this old question again striked me. When we talk about pointers in C, simple pointers are easy to undertand, but for me array pointers didn't make sense (as I could never undertand them).
int x[] = {1, 2, 3};
int *y[] = {4, 5, 6};
In the above code, if I'll do printf("%u", x)
it'll give address of first element of x array, which clears the fact that x is a pointer to the array x. Similarly if I'll do printf("%u", y)
it'll give address of first element of y array.
So what makes x different from y? Can someone please explain.
P.s. I'm not asking about regular pointers, I'm very well verse with the concept of pointers.
int x[] = {1, 2, 3};
defines array of 3 integersint *y[] = {4, 5, 6}
defines array of 3 pointers and inializes it with integers converted to pointers which basically makes no sense. In such array you want to store references (pointers) to objectsNo, It invokes Undefined behaviour as you use the wrong format specifiers. You need to
printf("%p", (void *)x);