int main()
{
int a[3]={1,10,20};
printf("%u %u %u \n" ,&a,a,&a[0]);
return 0;
}
This prints the same value for all three.
I understand that a and &a[0] is same but how is &a also same?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For maximum compatibility you should always use
%pand explicitly cast tovoid*to print pointer values withprintf.When the name of an array is used in an expression context other than as the operand to
sizeofor unary&it decays to a pointer to its first element.This means that
aand&a[0]have the same type (int*) and value.&ais the address of the array itself so has typeint (*)[3]. An array object starts with its first element so the address of the first element of an array will have the same value as the address of the array itself although the expressions&a[0]and&ahave different types.