图书简介:
第1 章 绪论 ··································.1
1.1 程序设计语言的发展 ············.1
1.1.1 程序 ························.1
1.1.2 程序设计 ··················.1
1.1.3 程序设计语言 ············.2
1.2 C 语言 ·······························.3
1.2.1 C 语言的特点 ·············.3
1.2.2 C 语言的结构 ·············.6
1.3 几个简单的 C 语言程序 ··········.6
1.4 C 语言程序的结构特点 ··········.9
1.5 C 语言程序的开发设计
过程 ··································.9
1.6 程序设计的过程 ················.10
1.7 书写程序时应遵循的规则 ·····.11
1.8 对于 C 语言学习的认识 ·········.11
习题 ······································.12
第2 章 基本数据类型及运算符 ········.15
2.1 C 语言的字符集、关键字
和标识符 ··························.15
2.1.1 字符集 ···················.15
2.1.2 关键字 ···················.15
2.1.3 标识符 ···················.16
2.2 C 语言的数据类型 ··············.16
2.2.1 数据及数据类型
的概念 ···················.16
2.2.2 基本类型 ················.17
2.2.3 构造类型 ·················.17
2.2.4 其他类型 ·················.17
2.3 常量与变量 ·······················.18
2.3.1 常量 ·······················.18
2.3.2 变量 ·······················.19
2.4 整型数据 ··························.20
2.4.1 整型常量 ·················.20
2.4.2 整型变量 ·················.21
2.5 实型数据 ··························.23
2.5.1 实型常量 ·················.23
2.5.2 实型变量 ·················.23
2.6 字符数据 ··························.23
2.6.1 字符常量 ·················.23
2.6.2 转义字符 ·················.24
2.6.3 字符变量 ·················.24
2.6.4 字符串常量 ··············.25
2.7 运算符和表达式 ·················.26
2.7.1 算术运算符和
算术表达式 ··············.27
2.7.2 赋值运算符和
赋值表达式 ··············.28
2.7.3 自增、自减运算符 ····.30
2.7.4 逗号运算符和
逗号表达式 ··············.31
2.7.5 sizeof 运算符 ············.31
2.7.6 位运算 ····················.32
2.8 运算符的优先级 ·················.35
2.9 混合运算中的类型转换问题 ·.36
2.9.1 自动类型转换 ··········.36
2.9.2 强制类型转换 ··········.37
2.10 小结 ······························.38
习题 ······································.39
第3 章 顺序结构 ··························.42
3.1 C 语言语句 ·······················.42
3.2 数据的输出和输入 ·············.43
3.2.1 printf( )函数和
scanf( )函数 ·············.43
3.2.2 其他输入输出函数 ····.50
3.3 顺序结构程序设计举例 ·······.53
3.4 小结 ································.58
习题 ······································.58
第4 章 分支结构 ··························.62
4.1 逻辑判断 ·························.62
4.1.1 关系运算符与
关系表达式 ·············.62
4.1.2 逻辑运算符和
逻辑表达式 ·············.63
4.1.3 条件运算符 ·············.65
4.2 if 语句 ·····························.66
4.2.1 if 语句的简单形式 ·····.66
4.2.2 if…else 语句 ············.69
4.2.3 if…else if…else
语句 ······················.73
4.2.4 if 语句的嵌套 ···········.76
4.3 if 语句应用举例 ·················.79
4.4 switch 语句 ·······················.83
4.5 无条件转移语句(goto) ·····.87
4.6 小结 ································.88
习题 ······································.88
第5 章 循环结构 ··························.92
5.1 while 语句 ························.92
5.1.1 while 语句的结构 ······.93
5.1.2 while 语句的使用 ······.95
5.2 do…while 语句 ··················.100
5.2.1 do…while 语句的
结构 ······················.100
5.2.2 do…while 语句的
使用 ······················.101
5.3 for 语句 ···························.103
5.3.1 for 语句的结构 ·········.103
5.3.2 for 语句的使用 ·········.105
5.4 循环中 break 和 continue
语句的使用 ······················.108
5.5 循环语句的嵌套 ················.111
5.6 3 种循环的比较 ·················.113
5.7 循环语句的综合应用 ··········.114
5.8 小结 ·······························.119
习题 ······································.119
第6 章 函数 ·······························.124
6.1 函数的概念 ······················.124
6.1.1 库函数 ···················.125
6.1.2 自定义函数 ·············.125
6.1.3 自定义函数的调用 ···.128
6.2 变量的作用域和存储类别 ····.133
6.2.1 变量的作用域 ··········.134
6.2.2 变量的存储类别·······.137
6.3 内部函数和外部函数 ··········.141
6.3.1 内部函数 ················.141
6.3.2 外部函数 ················.141
6.4 函数的递归调用 ················.142
6.5 模块程序设计实例 ·············.146
6.6 小结 ·······························.156
习题 ······································.157
第7 章 数组 ·······························.162
7.1 一维数组 ·························.163
7.1.1 一维数组的定义·······.163
7.1.2 一维数组的初始化 ···.164
7.1.3 一维数组的引用·······.164
7.2 二维数组及多维数组 ··········.170
7.2.1 二维数组的定义 ······.170
7.2.2 二维数组的初始化 ···.170
7.2.3 二维数组元素的
引用 ·····················.171
7.2.4 三维数组及讨论 ······.172
7.2.5 二维数组的应用 ······.172
7.3 字符数组与字符串 ············.174
7.3.1 字符数组和字符串
的初始化 ···············.174
7.3.2 常用字符串库函数 ···.178
7.3.3 字符数组与字符串
的应用 ··················.180
7.4 数组作为函数的参数 ·········.183
7.5 数组综合应用举例 ············.186
7.6 小结 ·······························.192
习题 ·····································.193
第8 章 指针 ·······························.199
8.1 变量的地址和指针 ············.199
8.1.1 指针变量的定义 ······.200
8.1.2 指针运算符 ············.200
8.1.3 指针的运算 ············.203
8.1.4 指针运算符与单目
运算符的优先级 ······.204
8.2 指针变量作为函数参数 ······.207
8.3 多级指针 ························.210
8.4 指针与数组 ·····················.211
8.4.1 指针与一维数组 ······.211
8.4.2 指针与二维数组 ······.213
8.4.3 数组指针 ···············.215
8.4.4 指针数组 ···············.216
8.5 指向函数的指针 ···············.217
8.5.1 指向函数指针的
定义 ·····················.217
8.5.2 指向函数指针的
引用 ·····················.217
8.6 命令行参数的使用 ············.220
8.7 指针应用程序举例 ············.222
8.8 小结 ·······························.225
习题 ······································.225
第9 章 用户自定义数据类型 ··········.230
9.1 结构类型 ·························.230
9.1.1 结构类型的定义·······.230
9.1.2 结构类型变量的
定义 ······················.231
9.1.3 结构类型变量的
初始化和引用 ··········.233
9.1.4 结构类型数组 ··········.237
9.1.5 结构类型指针 ··········.239
9.1.6 结构体在函数中的
使用 ······················.240
9.1.7 链表的概念及
简单应用 ················.245
9.2 位域 ·······························.258
9.3 联合类型 ·························.260
9.4 枚举类型 ·························.263
9.5 数据类型别名的定义 ··········.267
9.6 小结 ·······························.269
习题 ······································.270
第10 章 文件 ······························.274
10.1 文件的概念 ····················.274
10.1.1 C 语言中的文件 ······.274
10.1.2 标准级(流式)
输入输出 ················.274
10.1.3 文件指针 ··············.275
10.2 文件的打开与关闭 ···········.275
10.2.1 文件的打开 ···········.275
10.2.2 文件的关闭 ···········.276
10.3 常用文件读写函数 ···········.278
10.3.1 字节级读写函数 ·····.278
10.3.2 字符串级读写
函数 ······················.280
10.3.3 格式化读写函数 ·····.281
10.3.4 块读写函数 ···········.284
10.4 文件定位与随机读写 ········.287
10.5 文件操作错误检测 ···········.289
10.6 小结 ·····························.290
习题 ·····································.290
第11 章 预处理命令 ·····················.294
11.1 宏定义 ··························.294
11.1.1 无参数的宏定义 ·····.294
11.1.2 带参数的宏定义 ·····.298
11.2 文件包含 ·······················.300
11.3 条件编译 ·······················.301
11.3.1 第 1 种条件编译 ······.301
11.3.2 第 2 种条件编译 ······.302
11.3.3 第 3 种条件编译 ······.302
11.4 小结 ·····························.304
习题 ······································.304
附录A 常用库函数 ·······················.307
A.1 数学函数 ························.307
A.2 字符函数和字符串函数 ······.308
A.3 输入输出函数 ··················.309
A.4 动态存储分配函数 ············.311
附录B 常用字符与ASCII 码
对照表 ·····························.312
参考文献 ······································.314
展开
教育是国之大计、党之大计。党的二十大报告首次将“实施科教兴国战略,强化现代化建设人才支撑”作为一个单独部分,充分体现了教育的基础性、战略性地位和作用,并对“加快建设教育强国、科技强国、人才强国”作出全面而系统的部署,为到 2035 年建成教育强国指明了新的前进方向。
教材是落实立德树人根本任务的重要载体,是育人育才的重要依托。本书编者组织了部分长期从事“C 语言程序设计”课程教学的教师,在 2011 版、2015 版、2021 版的基础上,对原有内容进行了修订。此次修订将课程的两个核心教学目标(培养计算思维能力和编程能力)融入所有章节中,贯穿学生学习的全过程。此外,针对部分初学者感觉课程入门比较
难、不易掌握等问题,以及教学团队在教学过程中发现的一些问题,本书编者在修订时以“易学”“案例丰富”两条主线贯穿全书,并使学习内容层次化、模块化、知识点化,在例题的选择、教学案例的叙述方式等方面做了改进。
本书精心挑选了 90 多个程序实例,并特别注意各实例之间的联系。很多实例以两种形式出现,这样做的目的是引导读者用新知识重新编写原来的程序,并对原来较小的程序进行扩充、组合,使之成为较大、较复杂的程序。用新结构重新编写学过的程序,可以有效地复习原有知识,加深对新知识的理解。
习近平总书记在党的二十大报告中指出,要推进教育数字化,建设全民终身学习的学习型社会、学习型大国。教育数字化是教育教学活动与数字技术融合发展的产物,也是进一步推动教育改革发展的重要动力。本书在超星慕课平台上建设了配套的课程资源,读者可以根据需要进行线上学习以及下载各类教学资源。
全书由孙辉、吴润秀担任主编,朱华生、叶军、冯祥胜、韩宇贞、田秀梅担任副主编。朱华生与吴润秀合作编写了第 1 章、第 2 章,孙辉和田秀梅合作编写了第 3 章、第 4 章,孙辉和韩宇贞合作编写了第 5 章、第 6 章,叶军编写了第 7 章、第 8 章,冯祥胜编写了第 9章、第 10 章,孙辉编写了第 11 章。孙辉、叶军组织了全书的统稿及校对工作。
本书是针对 C 语言的初学者编写的。为了适应中级读者,也为了使初学者尽快提高水平,从第 7 章开始内容难度有了较大幅度的提升。有些程序较长,并有一定的难度,但只要读者能将程序输入计算机中并调试通过,再跟踪程序的运行情况,就不难理解这些程序。本书所有程序均在 Visual C++ 2010 编译器中编译、调试通过。
由于计算机技术的发展日新月异,加上编者水平有限,书中疏漏之处在所难免,敬请专家、教师和广大读者不吝指正(2003992646@nit.edu.cn)。
展开