Pointers are not integers, which is more like unsigned integers. However, you print them as if they were whole integer characters. On a 32-bit system, there are several things that can be 32 bits long: int , unsigned int , float and pointers. You cannot say at all that it is just by looking at them, but they all mean different things. (As an experiment, you can pass various integers and print them as a float and vice versa: this is bad practice in general, but it can show you that different data types mean different things.)
Functions that take a variable number of arguments ("variational" functions) make this difficult. In particular, they do not check argument types. You can pass any arguments you like printf() and similar functions, but getting them to agree with the format specifier is your problem. This means that the function has no way to get the correct type (as if you passed the float a function like int foo(int) ).
Passing the wrong argument types leads to undefined behavior and is more likely to cause problems if you pass arguments of the wrong size. On most 64-bit systems, pointers have 64 bits and int have 32 bits.
So you need to use the right thing in the format string. printf("%p", &a); will print address a as the pointer you want. The standard requires something like printf("%p", (void *)&a); , but as a practical question, unnecessary on any computer that you ever come across.
David thornley
source share