Structure memory allocation

struct node{
  int data;
  struct node * next;
};

How the compiler allocates memory for the "next" member when we have not allocated memory for the "struct node" structure yet

+3
source share
4 answers

nextmember is a pointer - a variable that will contain the address node, not node. All data type pointers are usually the same size, so it is enough for the compiler to know that it is a pointer that can calculate its size.

+3
source

The next element is a pointer. Pointers are the same size, so the compiler does not need to know how big a thing the next may refer to.

+17
source

- , , + int + padding node struct

+7

, malloc. . 4 , "" . , ( )

0

Source: https://habr.com/ru/post/1715514/


All Articles