往期回顾
1.【第一章】《认识C语言》
2.【第二章】C语言概述及基本知识1
3.【第二章】C语言概述及基本知识2
4.【第三章】字符串和格式化输入/ 输出
5.【第三章】 printf
6.【第三章】 scanf
7.【第三章】 putchar
8.【第三章】 getchar
9.【第三章】 sizeof
10.【第三章】 strlen
11.【第三章】 define
12.【第四章】运算符第一节
13.【第四章】运算符第二节
14.【第四章】运算符第三节
15.【第四章】运算符第四节
16.【第四章】类型转换
17.【第四章】函数与转化
18.【第五章】while
19.【第五章】for开篇
20.【第五章】for的灵活性
文章目录
- 往期回顾
- 逗号运算符
逗号运算符
逗号运算符扩展了for循环的灵活性,以便在循环头中包含更多的表达式。
例如演示了一个打印一类邮件资费。
#include <stdio.h>
int main(void)
{const int FIRST_OZ = 46; // 2013 rateconst int NEXT_OZ = 20; // 2013 rateint ounces, cost;printf(" ounces cost\n");for (ounces=1, cost=FIRST_OZ; ounces <= 16; ounces++,cost += NEXT_OZ)printf("%5d $%4.2f\n", ounces, cost/100.0);return 0;
}