#include<cstdio>
#include<iostream>
using namespace std;
typedef struct Student///结构体本名(可以不要)
{
char name[20];
int age;
}stu;///结构体别名(typedef定义了这种结构体类型的别名)
///这样定义对象的时候:本名/别名+对象名
int main()
{
Student student1={"guo",20};
}
本文深入探讨了C++中结构体的定义与使用,通过实例展示了如何利用typedef为结构体类型创建别名,简化了对象声明过程。文章通过具体代码示例,讲解了结构体成员初始化的方法。
#include<cstdio>
#include<iostream>
using namespace std;
typedef struct Student///结构体本名(可以不要)
{
char name[20];
int age;
}stu;///结构体别名(typedef定义了这种结构体类型的别名)
///这样定义对象的时候:本名/别名+对象名
int main()
{
Student student1={"guo",20};
}
2403

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