Three ways to define a struct variable
First, define the struct type, and then define the struct-body variable
General form:
struct STU_INFO
{
Char name[12];
int num;
Char id_card[19];
int G_score;
int X_score;
int S_score;
};
Defining struct-Body variables stu1,stu2
struct Stu_info stu1, stu2;
The second method, defining struct-body types while defining struct-body variables
General form:
struct STU_INFO
{
Char name[12]; /* Student Name */
int num; /* Student Number */
Char id_card[19]; /* ID Number */
int M_score; /* Math Results */
int C_score; /* Language score */
int H_score; /* Historical Results */
}STU1,STU2;
The third method, directly defines the structure of the variable
struct
{
Char name[12]; /* Student Name */
int num; /* Student Number */
Char id_card[19]; /* ID Number */
int M_score; /* Math Results */
int C_score; /* Language score */
int H_score; /* Historical Results */
}STU1,STU2;
When you define a variable directly with a nameless struct, you can only define it once, and this method is not recommended.
Storage structure of struct variables:
1. Structure variable storage structure: In general, each member is stored continuously, occupying space for the sum of the space occupied by each member.
2. It is common to use sizeof to calculate the size of a struct or struct variable that requires space to be allocated, regardless of specific details.
C + + struct Body (iii)