Print adresses with printf %016x vs %p on 64bit systems

c, pointers, printf

Solution

To print pointers in `printf`, using `%p` with `void *` type is the way according to the C standard.

printf("%p", (void *)&var);

Problem

I have some trouble with a book that I am currently reading about C and assembly. The author uses a 32 bit environment while I am using 64-bit. The problem is that the author often uses ``` printf("%08x", &var); ``` To print addresses which works fine on 32 bit. But when I run this on 64-bit I get only half of the address while `%p` gives me the whole address... So why is this so? I of course use `%016x`instead of `%08x`. The author only uses `%p` for pointers. So when should I use what?

Original source

Related problems