how to see address of a structure in printf

EDIT: Don't do this! It prints the address of the pointer, not what you want!

I had all kinds of trouble getting this to work, but here's something that the compiler (I use the simple "cc" unix command line) didn't complain about and seemed to give appropriate results:

struct node temp;
// ... whatever ...
printf ("the address is %p", &temp);

[Rather than deleting, I left this as an example of what NOT to do. -smb]


Use the pointer address format specifier %p:

printf("Address: %p\n", (void *)temp);

Tags:

C

Pointers

Struct