I've thought that a[0]
is equivalent to *a
, but then I came across this piece of code:
int arr[] = {1, 2, 3};
int (* a)[] = &arr;
printf("%d", (*a)[2]); // compiles
printf("%d", a[0][2]); // errors out
There is a pointer to an array of unspecified size. The first expression compiles nicely, yet the second one results in
test.c:8:21: error: invalid use of array with unspecified bounds
printf("%d", a[0][2]);
^
The error from Clang is
error: subscript of pointer to incomplete type 'int []'
and from MSVC v19.10
error C2036: 'int (*)[0]': unknown size
Why isn't a[0]
equivalent to *a
?