Re: Output of the printf(a,*a,**a) where a is of type int [][][]
Nikhil Bokare said:
> Thanks for pointing out my mistakes.
> This is my edited program:
>
> #include<stdio.h>
>
> int main()
> {
> int a[3][3][3];
> printf("%p %p %p %p",a,*a,**a,&a);
That line should be:
printf("%p %p %p %p",(void *)a,(void *)*a,(void *)**a,(void *)&a);
> return 0;
> }
>
> Its still printing the same value for all of them. How does it happen??
They have different types, as I explained before, so they have different
values, as I explained before. The casts to void * are required, as I
explained before. Because the casts to void * discard type information,
the differences between the values are also being discarded.
Here's a real world parallel question:
"I used a GPS to find out the location of an oxygen atom, a water molecule,
and a water spillage on a kitchen table, and the GPS gave the same
location for all three. Why?"
Obviously, these are three very different things. Equally obviously,
there's no particular reason why they shouldn't be in precisely the same
place.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|