1,三种初始化方法
1.先定义类型,再定义变量
strut Student{
int age;
char* name;
};
struts Student stu;
2.定义类型的同时定义变量
strut Student{
int age;
char* name;
} stu;
struts Student stu2;
3.定义类型的同时定义变量(省略了类型名称)
strut {
int age;
char* name;
} stu;
2,结构体初始化
struts Student stu={2,'name'};
stu.age=3;
struts Student stu={.name='name',.age=11};
3,结构体数组
strut Student{
int age;
char* name;
} ;
struts Student stu[3]={
{2,'name1'},
{3,'name2'},
{4,'name3'}
};
stu[0].age=9;
本文介绍了C语言中结构体的三种定义方式及初始化方法,并展示了结构体数组的使用实例。

被折叠的 条评论
为什么被折叠?



