I read this in my book (and many sources on the internet):
The array variable points to the first element in the array.
If this true, then the array variable and the first element are different. Right?
It means by below code, it will produce two different results:
int main(){
char msg[] = "stack over flow";
printf("the store string is store at :%p\n",&msg);
printf("First element: %p\n",&msg[0]);
}
But I receive the same results for the two cases. So, by this example, I think we should say: the array variable is the first element. (because it has the same address)
I don’t know if this true or wrong. Please teach me.
The array variable signifies the entire memory block the array occupies, not only the array’s first element. So
arrayis not the same asarray[0](cf.sizeof array / sizeof array[0]). But the array’s first element is located at the same memory address as the array itself.Saying the array points to the first element is also incorrect, in most circumstances, an array expression decays into a pointer to its first element, but they are different things (again cf.
sizeoffor example).