Reputation: 2238
I have the following code:
int arr[2][2][2]={10,3,4,5,6,7,8,9};
int *p;
printf("%u",arr);
p=(int *)arr;
printf("%u",p);
Which outputs
64166
64164
But I would think that p
and arr
point to the same memory address. Why are different addresses shown?
Upvotes: 2
Views: 156
Reputation: 9504
But same code
#include <stdio.h>
int main()
{
int arr[2][2][2]={10,3,4,5,6,7,8,9};
int *p;
printf("\n%u",arr);
p=(int *)arr;
printf("\n%u\n",p);
return 0;
}
gives same result only.
Upvotes: 2
Reputation: 7156
Let's walk through the code
int *p;
printf("%u",p);
p is an unitialized int pointer. It is going to print out whatever is in memory.
p=(int *)arr;
printf("%u",p);
p now is pointing to the address of the array in memory, and prints that address.
Upvotes: 2