本书共分11章,第1章介绍了程序设计基本知识、C语言基本概念、特点和结构等;第2章介绍了C语言中数据类型、常用的运算符、算术表达式和数据类型间的运算等;第3章介绍了C语言中常用的输入、输出函数以及顺序结构的程序设计方法;第4章介绍了关系运算符、逻辑运算符、条件运算符、if语句的三种形式及switch语句;第5章介绍了C语言中while、do…while和for三种循环语句、控制语句break、continue和循环的嵌套;第6章介绍了自定义函数的定义、自定义函数的调用、 函数的递归调用、变量的存储类型和外部函数与内部函数;第7章介绍了数组的定义、初始化和引用、常用字符串函数、数组名作函数参数等;第8章介绍了指针变量的定义与赋值、常用的针运算符、参数指针的使用、多级指针和指针与数组的关系;第9章介绍了户自定义数据类型的基本概念、结构体类型的定义、结构体变量定义、初始化和引用;typedef定义类型、结构体指针和链表等;第10章介绍了文件的基本概念、文件指针的定义及赋值和常用的文件操作函数;第11章介绍了预处理命令的基本概念、不带参的宏定义、带参数的宏定义、文件包含和条件编译的基本用法。每一章都配备了一定数量的习题。
孙辉,1959生,男,教授,硕士研究生导师。江西省政协委员,南昌工程学院信息工程学院院长。全国水利水电类专业教学指导委员会委员;中国人工智能学会粗糙集与软计算专业委员会委员;江西省高校"十一五”、"十二五”计算机应用技术重点学科带头人;南昌市"五一”劳动奖章获得者;水利部及江西省优秀教师;首届江西省普通高校教学名师奖获得者。
第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