&a is the "array address". This is the place in memory where the array is located, but it has a special pointer to the array from.
&a[0] is the "address of the 0th element of the array". Since there is nothing in the element until the 0th element, this is the same place in memory, but with the type "pointer to".
a is an "array". But you cannot pass arrays by value in functions (e.g. printf ) in C or C ++. You can only pretend to do this. (In C ++, you can pass arrays by reference, but C has no gaps). But what really happens is that the array "decays" into a pointer to the first element, just as if you wrote &a[0] .
This happened because (mainly I reflect here) in C, it was considered useful and desirable: (a) to be able to modify the contents of an array of transmitted ones; (b) no need to copy entire arrays onto the stack when calling a function. That way, C lies with you and instead pushes the pointer to the original array on the stack. Since the syntax is the same, you never notice the difference - when you write a[0] with what you think is an array, but is actually a pointer, it accesses pointed memory as if it were an array ( no matter what it is - thereโs no longer any way to tell). In C ++, behavior is maintained for backward compatibility.
Karl Knechtel
source share