[October 18 per day] self-reference structure

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.