The question is more of theory-based than practical implementation.
What I would like to know is, in the code:
struct temp {
int num;
struct temp *next;
};
In the structure made above, how does the compiler decide how much of space should be allocated in memory when we instantiate it?
If I try to dry-run the code, the size of an integer would be 2 or 4 bytes, after that, if I try to find the size of the pointer to the structure itself, I enter a structure containing another integer and a pointer to itself.
By this logic, the compiler would enter an infinite loop when deciding to allocate space to an element of this structure, how then is the space decided?
P.S. I did try to find out the size of this structure myself (using the sizeof()
operator, it turned out to be 16 bytes (the size of the integer being 4 bytes)... I'm interested in knowing how did it determine this figure of 16 bytes as the space required!