Self-reference structure of daily one CEvery day, I picked up a C-language shell, which grew up and formed thousands of miles.
Today's shells: Solve the doubts about the self-reference structure, and analyze the self-reference structure of struct1. Self-reference structure:The structure contains pointers to itself. Such struct structures are called self-reference structures. A commonly used linked list node is a self-reference structure.Struct node {Int number;Struct node * next; // pointer to the next node};2. traps:The pointer to itself contained in the structure isValidBut its own variables areInvalid. As follows:Struct node {Int number;Struct node copy; // a node variable};It will lead to infinite recursive definition, which is easy to understand. The structure contains the copy structure, and the copy structure is included in the copy structure... it will fall into an infinite loop trap.3. Why is the pointer okay?:First, the pointer pointing to itself will not trigger loop definition and will not fall into the loop trap. Second, the pointer has a fixed size and defines a struct. the compiler must know the memory occupied by this struct.
Have a nice day!