Per a different thread I learned that using '&' with an array doesn't return a double pointer but rather a pointer array.
int x[9] = {11, 22,33,44,55,66,77,88,99};
int (*xpt)[9] = &x; <---This is the focus of this thread.
The following code compiles and executes.
#include <stdio.h>
int main ()
{
int x[9] = {11, 22,33,44,55,66,77,88,99};
int (*xpt)[9] = &x;
printf("xpt[0] = %d\n", xpt[0]);
printf("xpt[0][0] = %d\n", xpt[0][0]);
printf("xpt[0][1] = %d\n", xpt[0][1]);
printf("*xpt[0] = %d\n", *xpt[0]);
printf("*xpt[1] = %d\n", *xpt[1]);
return 0;
}
Here is the output.
> ./runThis
xpt[0] = 155709776
xpt[0][0] = 11
xpt[0][1] = 22
*xpt[0] = 11
*xpt[1] = 32766
The questions pertain to the output. Since xpt is an array pointers (I assume) xpt[0] is simply displaying the address of the first value 11.
I was a bit surprised that the following 2 lines worked.
xpt[0][0] = 11
xpt[0][1] = 22
After thinking about it, it almost makes sense as I was thinking xpt[0] and *xpt could be used interchangeably until the following two lines disproved that :
*xpt[0] = 11
*xpt[1] = 32766
Why does *xpt[0] return the expected value but not *xpt[1]?
xptis a pointer to array of 9ints. Don't assume, but find the docs and verify.