- 4
- 0
- 约5.94千字
- 约 38页
- 2018-09-05 发布于江苏
- 举报
第10讲结构体与共用体
第10讲 结构体与共用体;10.1 结构类型与结构变量的定义;struct date /*日期结构类型:由年、月、日三项组成*/
{int year;
int month;
int day;
};
struct std_info /*学生信息结构类型:由学号、姓名、性别和生日共4项组成*/
{char no[7];
char name[9];
char sex[3];
struct date birthday;
};
struct score /*成绩结构类型:由学号和三门成绩共4项组成*/
{char no[7];
int score1;
int score2;
int score3;
}; ;(1)“结构类型名”和“数据项”的命名规则,与变量名相同。
(2)数据类型相同的数据项,既可逐个、逐行分别定义,也可合并成一行定义。
例如,本案例代码中的日期结构类型,也可改为如下形式:
struct date
{int year, month, day;
};
(3)结构类型
原创力文档

文档评论(0)