How can you interpret the following line of code?
int (*arrayABC)[10];
In my textbook, it says that we have a pointer to a pointer to the 0th element of an integer array.
However, I don't quite understand this.
My interpretation: We have some variable, which gets as its value some address. This address is then the address of the 0th element of an UNNAMED integer array. Basically we have a pointer to the 0th element.
Why then to have a pointer TO A POINTER?
When we allocate memory to a variable, pointer points to the address of the variable. Unary operator ( * ) is used to declare a variable and it returns the address of the allocated memory. Pointers to an array points the address of memory block of an array variable.
When we require multiple pointers in a C program, we create an array of multiple pointers and use it in the program. We do the same for all the other data types in the C program.
Pointer to an array points to an array, so on dereferencing it, we should get the array, and the name of array denotes the base address. So whenever a pointer to an array is dereferenced, we get the base address of the array to which it points.
-1 means the last element, -2 the second last, and so on.
This is a pointer to an array. It is not a pointer to a pointer. Arrays and pointers are different. An array has an address, but an array is not an address. An array is a series of contiguous elements.
This pointer points to the whole array and not just the first element, in the same way that a float *
points to the whole float and not just the first byte.
If you have for example:
int foo[10];
int (*arrayABC)[10] = &foo;
then the expressions (*arrayABC)
and foo
are identical. E.g. foo[3]
is the same as (*arrayABC)[3]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With