pointers - Confusion when assigning address using C -


i trying assign address of 1 of structure, named node, 1 named tmp, has same type--node. however, address of tmp less 8 address of node. why that? thanks!

  #include <stdio.h>   #include <stdlib.h>    typedef struct _node   {     int data;     struct _node *next;   }node;    int main()   {     node *node = (node*)malloc(sizeof(node));     node *tmp;     tmp = node;      printf("%d\n",&node);     printf("%d\n",&tmp);   } 

i guessing expected output same both lines.

for happen, have print values of pointers, not addresses of pointers.

after

tmp = node; 

the value of tmp same value of node addresses of 2 variables going different.

i suspect meant use:

printf("%p\n", node);  // use %p pointers, not %d printf("%p\n", tmp); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -