结构体与typedef

来源:互联网 发布:linux从服务器往电脑 编辑:程序博客网 时间:2024/05/16 07:18

c语言中结构体有两种表述方式:
1、使用typedef 相当于将stu变成了struct student的别名
/申明结构/
typedef struct student{ (第一行或typedef struct)
char name;
int year;
}stu;
/创建实例/
stu s1,s2;

2、不使用typedef
(1)struct sudent{

}
struct sudent s1,s2;

(2)struct student{
char mm[4];
}s1; 直接创建结构体student及其实例s1

(3)struct student{
char mm[4];
}s1={a,b,c,d}; 直接创建结构体student及其实例s1并初始化

0 0