Now i don't get why a and &a return the same value, what is the reasoning
a
is the name of the array that decays to pointer to the first element of the array.
&a
is nothing but the address of the array itself, although a
and &a
print the same value their types are different.
Also what is the type of &a?
Pointer to an array containing three int
s , i.e int (*)[3]
could i also do &(&a) ?
No, address of operator requires its operand to be an lvalue. An array name is a non-modifiable lvalue so &a
is legal but &(&a)
is not.
Printing type of &a
(C++ Only)
#include <typeinfo>
#include <iostream>
int main()
{
int a[]={1,2,3};
std::cout<< typeid(&a).name();
}
P.S:
Use %p
format specifier for printing address(using incorrect format specifier in printf
invokes Undefined Behavior)