Xylene23 Xylene23 - 15 days ago 4x
C Question

Pointers of Array in C

#include <stdio.h>

void main()
int a[]={1,2,3,4};

printf("%u %u ",a ,&a); //a
printf("%d %d ", *a ,*&a); //b

In ath line the output of
are same address but in bth line
does not give me the answer as

I know that
means pointer to array of integers but as the address is same, it should print


a decays to the pointer to the first element of the array.
&a is the pointer to the array of 4 ints.

Even though the numerical values of the two pointers are the same, the pointers are not of the same type.

Type of a (after it decays to a pointer) is int*.
Type of &a is a pointer to an array of 4 ints - int (*)[4].

Type of *a is an int.
Type of *&a is an array of 4 ints - int [4], which decays to the pointer to the first element in your expression.

The call

printf("%d %d ", *a ,*&a);

is equivalent to:

printf("%d %d ", *a , a);

BTW, You should use %p for pointers. Otherwise, you invoke undefined behavior. Increase the warning level of your compiler to avoid making such errors.