#include<stdio.h>
int main(void) {
int a[3] = {1,2,3};
printf("\n\t %u %u %u \t\n",a,&a,&a+1);
return 0;
}
Now i don’t get why a and &a return the same value, what is the reasoning and the practical application behind it? Also what is the type of &a and could i also do &(&a) ?
ais the name of the array that decays to pointer to the first element of the array.&ais nothing but the address of the array itself, althoughaand&aprint the same value their types are different.Pointer to an array containing three
ints , i.eint (*)[3]No, address of operator requires its operand to be an lvalue. An array name is a non-modifiable lvalue so
&ais legal but&(&a)is not.Printing type of
&a(C++ Only)P.S:
Use
%pformat specifier for printing address(using incorrect format specifier inprintfinvokes Undefined Behavior)