In a common struct , the size of a struct equals the sum of size of all its members, however when I want to apply this for the linked list based on struct ,it does not hold.
I run the following code on a 64-bit windows system, and my complier is gcc
typedef struct node {
int val;
struct node *head;
} node_t;
typedef struct point
{
int x;
int y;
} point_t ;
int main(){
point_t a = {1,1};
node_t b={1,NULL};
printf("%d %d %d\n",sizeof(node_t),sizeof(b.head),sizeof(b.val));
printf("%d %d %d",sizeof(point_t),sizeof(a.x),sizeof(a.y));
}
the output turns out to be
16 8 4
8 4 4
what I expect is that sum of sizeof(b.val)
and sizeof(b.head)
should euqual sizeof(node_t)
just as what happens for sizeof(point_t),sizeof(a.x),sizeof(a.y)
.
so is there anything special of the struct that forms a linked list in the storage?