c中的结构体嵌套问题
Structures in C language are basically user-defined data types that enables the user to create a data type that can group elements of different data types into it.
C语言的结构基本上是用户定义的数据类型 ,使用户能够创建一个数据类型,该数据类型可以将不同数据类型的元素分组到其中 。
Thus, it contains different data types to be represented by a single Structure name.
因此,它包含由单个结构名称表示的不同数据类型。
用C创建结构 (Creating Structures in C)
C language uses the struct
keyword to create a structure.
C语言使用struct
关键字创建结构。
Syntax:
句法:
struct Structure_Name
{
Datatype data_member1;
Datatype data_member2;
.
.
Datatype data_memberN;
};
As mentioned above, C language uses the struct keyword to build a structure. Inside the curly brackets, the user can define the data members necessary to serve the purpose of the particular program. These data members are the basic C language variables of different data types such as int, float, double, char, etc.
如上所述,C语言使用struct关键字来构建结构。 在大括号内,用户可以定义实现特定程序目的所需的数据成员。 这些数据成员是不同数据类型(例如int,float,double,char等)的基本C语言变量。
It is mandatory to add a semi-colon (;) after the closing curly bracket of a particular structure.
强制在特定结构的右花括号后添加分号(;)。
Example:
例:
struct Student_info
{
char name[100];
char address[100];
char division[50];
int roll_num;
};
In the above code snippet, we have created a structure as Student_info to serve the purpose of Student Information. Within the structure, we have declared data members: name, address, division, and roll_num with their particular data type.
在上面的代码片段中,我们创建了一个名为Student_info的结构来满足学生信息的目的。 在结构中,我们声明了数据成员: name , address , division和roll_num及其特定的数据类型 。
声明结构变量 (Declaration of Structure Variables)
Structur