-2

The output of the programmer :

#include<stdio.h>
int main (){
 int A[3] = {1,2,3};
printf("%u %u %u ",&A,A,*A); 
return 0;
}

is :3216303812 3216303812 1

here &A and A is same that means address of a is same as the value of a i.e A is pointing to itself. and *A means value stored at 3216303812 which is A itself as we know &A = A.. so where is the 1 coming from ?? how come *A = 1 ? Please help

user2588495
  • 93
  • 1
  • 5

2 Answers2

5

A is a pointer to the first element of the array, i.e. it's equivalent to &A[0].

&A is a pointer to the entire array.

Of course these addresses have the same value, since the address of the first element of an array is the same as the address of the array. However they have different types: A yields a pointer to int, whereas &A is a pointer to an array of int.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Thanks Carl , actually i wanted to understand the memory arrangement for the same, As A is the starting address of the array, so ideally memory arrangement should have been something like , at 3216303812 ->1 (i,e *A), at 3216303816 -> 2(i.e *(A+1)) and at 3216303812 ->3 (i.e *(A+2)). But *A is equivalent to *(3216303812) , and i am seeing at memory address 3216303812 we have A , because &A=3216303812 , and A is 3216303812 , so *A should be 3216303812. Please correct me where i am going wrong. – user2588495 Jul 16 '13 at 18:53
  • @user2588495: read the answer above again, carefully - understand that `A` and `&A` are different *types*, even though they have the same *value* (address). – Paul R Jul 16 '13 at 19:45
0

A means &A[0], so *A is equivalent to value of first element in array, hence output is 1.

dejavu
  • 3,236
  • 7
  • 35
  • 60