How to see address of a structure in printf


I have a function which returns address as following

struct node *create_node(int data)
        struct node *temp;
        temp = (struct node *)malloc(sizeof(struct node));
        printf("create node temp->data=%d\n",temp->data);
        return temp;

where struct node is

struct node {
        int data;
        struct node *next;

How can I see in printf("") the address stored in temp?

If I check the adressed in gdb the addresses are coming in hex number format i.e.
0x602010 where as same address in printf("%p",temp) is coming in a different number which is different from what I saw in gdb print command.

Best Solution

Use the pointer address format specifier %p:

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