So, I always knew that the array “objects” that are passed around in C/C++ just contained the address of the first object in the array.
How can the pointer to the array “object” and it’s contained value be the same?
Could someone point me towards more information maybe about how all that works in assembly, maybe.
Short answer: A pointer to an array is defined to have the same value as a pointer to the first element of the array. That’s how arrays in C and C++ work.
Pedantic answer:
C and C++ have rvalue and lvalue expressions. An lvalue is something to which the
&operator may be applied. They also have implicit conversions. An object may be converted to another type before being used. (For example, if you callsqrt( 9 )then9is converted todoublebecausesqrt( int )is not defined.)An lvalue of array type implicitly converts to a pointer. The implicit conversion changes
arrayto&array[0]. This may also be written out explicitly asstatic_cast< int * >( array ), in C++.Doing that is OK. Casting to
void*is another story.void*is a bit ugly. And casting with the parentheses as(void*)arrayis also ugly. So please, avoid(void*) ain actual code.