Some times the when you print addresses using %d it will show as
negative, but we know that addresses cant be negative. So we should
use %u as format specifier.
As far as C itself is concerned, addresses are not integers. In
particular, they are not comparable with < and > except within a
single object. So from C's point of view it doesn't make much sense
to ask whether an address is negative. And this is true on some
hardware: who can say whether a pointer represented as a segment
number and offset is positive or negative?
Of course, most modern hardware uses a flat address space within
single programs, and by convention the addresses are non-negative. On
such systems converting a pointer to a sufficiently large unsigned
integer type will usually give you the value you expect. If addresses
happen to fit in an unsigned int, then printing them as %u will
give you the expected answer.
But you don't usually need to make such an assumption. The format
specifier %p exists for just this purpose: it converts a void pointer
to a textual form that is appropriate for the system.
You may disagree with the implementation about what form is
appropriate. You might like addresses displayed in decimal rather
than hex, for example. In that case you can cast your pointer to an
appropriately sized int and print it with an appropriate format, but
you've given up a certain amount of portability.
-- Richard