Structural Summary 2

Source: Internet
Author: User

Structs and pointers and linked lists
Declaration of the struct body
A struct is a type that contains a number of different types of variables
struct student
{
Char name[20];
int age;
int number;
}
struct Student x;
struct student x[20],*x;
Both X and x[20],*x are of the same type at this point
Attention:
struct
{
int A;
Char b;
float C;
}x;
struct
{
int A;
Char b;
float C;
}y[20],*z;
Now the x,y,*z, is completely different type.
You can also declare a new data type using the typedef keyword
typefde struct Student
{
Char name[20];
int age;
int number;
}stu;
Later you want to declare this structure to use Stu, of course, you can also use Stu to declare pointers
STU one;
STU *p;
p=&one;
This is all a legal way to use it. You will be able to access the name through P->name.
Self-referential behavior of structs
struct student
{
int A;
struct student *b;
int C;
}
This reference is legal except that the pointer points to a different structure of the same type, which is mentioned in the list and data structure.
The initialization of a struct is similar to the initialization of an array, in which the declaration is initialized with curly braces.
In the case of using pointers, *p+1;* (p+1);p +1 is illegal, if one is an array then say otherwise,
Priority is higher than & priority
A struct is a bit like a pointer is a layer of structure
When declaring the various elements of a struct, it is advisable to have the most stringent members of the boundary appear first, and finally to the members with the weakest boundary requirements, which can be arrogant to reduce the space loss caused by the boundary.
For example
struct ALU
{
int A;
Char b;
char c;
};
Of course, for the maintainability of the program, you may not have to do this, but it is recommended
You can use Offsetof (type,member) to determine the bit value at which the specified member starts to store the bit values offset by a few bytes from the value of the structure that begins to store
It is better to call a pointer when invoking a struct, which is much more efficient, and it is much quicker and easier to apply it as a register variable.
Use the const keyword to prevent structural content from being modified



Structural Summary 2

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.