(e-mail address removed) said:
hi all i have simple Problem please tell me the Solution if u know??
main()
{
int a[3][3]={1,2,3,4,5,6,7,8,9};
printf("%u %u %u",a[0],a[1],a[2]);
}
You forgot to #include <stdio.h> - you'll need to fix that if you want to
use printf in your program, because its behaviour if you don't is allowed
to be arbitrary. You'll also want to use int main(void) rather than just
main(), and add a return statement to your function, e.g. return 0;
The problem with your program is that you are expecting printf to do more
than it can in fact do. It knows about chars, and unsigned chars, and
short ints, and unsigned short ints, and ints, and unsigned ints, and long
ints, and unsigned long ints, and doubles, and long doubles. It even knows
about pointers to void. But that's all it knows about, in the way of data
types.
a[0] is equivalent to *(a + 0), i.e. *a. (C doesn't let you use array
values, so in a value context like this, the value you actually get is a
pointer to the array's first element, i.e. a pointer to an array of three
int.) Dereferencing gives the array itself, i.e. an int[3], which decays
to an int *. But printf doesn't understand about pointers-to-int (except
in the pathological case of %n, which doesn't do what you want). And even
if it did, it wouldn't understand them in the context of %u, which is used
for printing unsigned ints, not pointers-to-int.
The proper course is to use %p as the format specifier and (void *)a[0] as
the argument.
Unfortunately, converting a pointer to some type (or an array of some
type!) into a void * is a bit like converting a place into GPS
co-ordinates. Contextual information is lost. Consider a house, a room, a
wall, a brick, and a "brick atom". All could have the same GPS co-ords,
even though they are very different things.
The right way to think about this is to work out exactly *why* you need to
know the information you're trying to display. The chances are that you
don't actually need it, and are merely curious - in which case, the proper
answer is that it doesn't /matter/ what glyphs are scribbled on your
screen when you print an address, provided only that you understand the C
type system. If you genuinely *do* need the information, it will either be
for a spurious reason (e.g. you're a student, and your teacher is stupid
enough to require you to find out this information) or for a real
technical reason. If the latter, you will be sufficiently experienced to
realise that you're trying to step outside the bounds of behaviour that C
can guarantee, and into the realms of architecture-specific details.