On page 103 in the book “Expert C Programming: Deep C Secrets” by Peter Van Der Linden there is a table about the difference between arrays and pointers.
One issue I don't really understand – direct quote:
Pointer: Typically points to anonymous data
Array: Is a named variable in its own right
What does this mean? Since you can do the following:
#include <stdio.h>
#include <stdlib.h>
int main(void){
int x[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int *y = malloc(9*sizeof(int));
printf("sizeof(x) == %zu\n", sizeof(x));
printf("&(x[2]) = %p\n", (void*)&(x[2]));
printf("sizeof(y) == %zu\n", sizeof(y));
printf("&(y[2]) = %p\n", (void*)&(y[2]));
return 0;
}
Output:
sizeof(x) == 36
&(x[2]) = 0x7fffffffe5f8
sizeof(y) == 8
&(y[2]) = 0x800e18008
I don't see how y
is less of a named variable than x
.