Solid learning of C language (2) structure and association

Source: Internet
Author: User

A question about struct:

Let's take A look at the Declaration of this struct and record it as

Struct node {int a; float B; struct node * next;} s;


And the following struct declaration, record it as B
Struct node {int a; float B; struct node next;} s;


What are their differences?


I learned chapter 3 of "C and pointer" today. I have never paid attention to this problem before. Now I have a deep understanding of the statements and definitions.

The Declaration is to tell the compiler about the size of the cookies made by the cookie server. However, the cookie server is not the cookie itself, but the cookie itself!

The struct declaration in B is incorrect because the compiler considers that an undefined identifier is used in the Code statement: struct node next, because the struct of struct node has not been declared as successful yet. Why? The Declaration is to tell the compiler how much space you should reserve for this variable. At this time, the size of the struct node struct is unknown, and the cookie server is not complete. Of course, the cookie cannot be used!


Struct node * In A is A pointer type. We know that the pointer type is 4 bytes on 32-bit windows machines. Therefore, when the compiler analyzes the code: struct node * next, you can know that the next variable is four bytes to complete the Declaration.


You will find that the next type can be correctly compiled for any struct pointer, for example, struct unknown * next. At this time, although struct unknown is not declared, it is also correct because, the compiler does not care about the specific labels at this time. I only care about my work, that is, allocating memory!

Related Article

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.