东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第11章 结构体与共用体

第十一章结构体与共用体 结构体 ■结构体是一种构造数据类型 ■把不同类型的数据组合成一个整体一一自定义数据类型 ■结构体类型定义 合法标识符 struct结构体名] 可省:无名结构体 struct关键字, 不能省略 类型标识符成员名 类型标识符成员名 成员类型可以是 基本型或构造型
第十一章 结构体与共用体 结构体 结构体是一种构造数据类型 把不同类型的数据组合成一个整体--自定义数据类型 结构体类型定义 struct 结构体名] { 类型标识符 成员名 ; 类型标识符 成员名 ; ……………. }; 成员类型可以是 基本型或构造型 struct关键字, 不能省略 合法标识符 可省:无名结构体

例 struct student num 字节 int num; char name 201; name ●●● 20字节 char sex: sex 1字节 int age float score: age 2字节 char addr30l; score 4字节 结构体类型定义描述结构 addr 30字节 的组织形式,不分配内存
struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }; name num sex age score addr 2字节 2字节 20字节 1字节 4字节 30字节 … ….. 结构体类型定义描述结构 的组织形式 ,不分配内存 例 :

结构体变量的定义 ■先定义结构体类型,再定义结构体变量 般形式 struct结构体名 类型标识符成员名; 类型标识符成员名; struct结构体名变量名表列;
先定义结构体类型,再定义结构体变量 一般形式: struct 结构体名 { 类型标识符 成员名; 类型标识符 成员名; ……………. }; struct 结构体名 变量名表列; 结构体变量的定义

例 struct student int num; char name 20]; char sex: int age; float score: char addr 30l; struct student stul stu2
struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }; struct student stu1,stu2; 例:

■定义结构体类型的同时定义结构体变量 般形式 struct结构体名 类型标识符成员名; 类型标识符成员名; 例 struct student }变量名表列; int num; char name 20; char sex: int age. float score: char addr 301; 3stul, stu2;
定义结构体类型的同时定义结构体变量 一般形式: struct 结构体名 { 类型标识符 成员名; 类型标识符 成员名; ……………. }变量名表列; 例 struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2;

用无名结构体直接 ■直接定义结构体变量 定义变量只能一次 一般形式 struct 类型标识符成员名 类型标识符成员名 struct }变量名表列; t int num; char name 201; char sex; int ages float score; char addr30b 3stul, stu2
直接定义结构体变量 struct { 类型标识符 成员名; 类型标识符 成员名; ……………. }变量名表列; 例 struct { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2; 用无名结构体直接 定义变量只能一次 一般形式:

说明: 结构体类型与结构体变量概念不同 类型:不分配内存;变量:分配内存 ■类型:不能赋值、存取、运算;变量:可以 ■结构体成员名与程序中变量名可相同,不会混淆 结构体可嵌套
结构体类型与结构体变量概念不同 类型:不分配内存;变量:分配内存 类型:不能赋值、存取、运算;变量:可以 结构体成员名与程序中变量名可相同,不会混淆 结构体可嵌套 说明:

例 struct date i int month; int day; int year; struct student birthday num name int num; month day year char name 20; struct date birthday;
例 struct date { int month; int day; int year; }; struct student { int num; char name[20]; struct date birthday; }stu; num name birthday month day year

例 struct student i int num; char name 20]; struct date i int month int day; birthday num name nt vear month day year birthday;
例 struct student { int num; char name[20]; struct date { int month; int day; int year; }birthday; }stu; num name birthday month day year

结构体变量的引用 ■引用规则:结构体变量不能整体引用,只能引用变量成员 引用方式:结构体变量名。成员名 成员(分量运算符 例 struct student 优先级:1 结合性:从左向右 int num; stulnum=10: char name[20; char sex, stul score=85.5 Int age; float score char addr301 stul score+=stu2 score 3stul, stu2 stulage++:
引用规则:结构体变量不能整体引用,只能引用变量成员 成员(分量)运算符 优先级: 1 结合性:从左向右 引用方式: 结构体变量名. 成员名 结构体变量的引用 例 struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2; stu1.num=10; stu1.score=85.5; stu1.score+=stu2.score; stu1.age++;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第10章 指针.ppt
- 东北电力大学:《C语言程序设计》C语言实验上机指导.doc
- 东北电力大学:《C语言程序设计》WORD讲义.doc
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第9章_预处理命令.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第8章_函数.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第7章_数组.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第6章_循环控制.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第5章_选择结构程序设计.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第4章_最简单的c程序设计.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第3章_数据类型、运算符与表达式.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第2章_程序的灵魂(算法).ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第1章_C语言概述.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第14章_常见错误和程序调试.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第13章_文件.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第12章_位运算.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第11章_结构体与共用体.ppt
- 清华大学出版社:《C语言程序设计》教材电子教案(PPT课件,第三版)第10章_指针.ppt
- 华中理工大学:《单片机原理与应用》课程电子教案(PPT课件讲稿)目录.ppt
- 华中理工大学:《单片机原理与应用》课程电子教案(PPT课件讲稿)第八章 微型计算机接口技术.ppt
- 华中理工大学:《单片机原理与应用》课程电子教案(PPT课件讲稿)第七章 I/O接口电路.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第12章 位运算.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第13章 文件.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第1章 C语言概述.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第2章 程序的灵魂-算法.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第3章 数据类型、运算符与表达式.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第4章 顺序结构程序设计.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第5章 选择结构程序设计.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第6章 循环结构程序设计.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第7章 数组.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第8章 函数.ppt
- 东北电力大学:《C语言程序设计》课程教学资源(PPT课件)第9章 预处理命令.ppt
- 北大青鸟:《SQLServer数据库》PPT教学课件 第一章 SQL Server数据库基础.ppt
- 北大青鸟:《SQLServer数据库》PPT教学课件 第二章 SQL Server数据库表管理.ppt
- 北大青鸟:《SQLServer数据库》PPT教学课件 第三章 SQL Server数据管理.ppt
- 北大青鸟:《SQLServer数据库》PPT教学课件 第四章 数据查询(1).ppt
- 北大青鸟:《SQLServer数据库》PPT教学课件 第五章 数据查询(2).ppt
- 厦门理工学院:《单片机原理与控制技术》课程教学资源(PPT课件讲稿,第2版)第1章 微型计算机系统基本知识.ppt
- 厦门理工学院:《单片机原理与控制技术》课程教学资源(PPT课件讲稿,第2版)第2章 80C51单片机内部结构和工作原理.ppt
- 厦门理工学院:《单片机原理与控制技术》课程教学资源(PPT课件讲稿,第2版)第3章 80C51系列单片机指令系统.ppt
- 厦门理工学院:《单片机原理与控制技术》课程教学资源(PPT课件讲稿,第2版)第4章 汇编语言程序设计.ppt