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