逗号表达式
来源:互联网 发布:纪元2070优化 编辑:程序博客网 时间:2024/05/16 05:32
1 逗号表达式
- 逗号表达式是C语言中的“粘贴剂”。
- 逗号表达式用于将多个子式连接为一个表达式。
- 逗号表达式的值为最后一个子表达式的值。
- 逗号表达式中的前N – 1个子式表达式可以没有返回值。
- 逗号表达式按照从左向右的顺序计算每个子表达式的值。
逗号表达式的示例(不好的使用方式)
#include <stdio.h>void hello(){ printf("Hello!\n");}int main(){ int a[3][3] = { (0, 1, 2), (3, 4, 5), (6, 7, 8) };//int a[3][3] = {2, 5, 8};此处为不当的逗号表达式 int i = 0; int j = 0; while( i < 5 ) printf("i = %d\n", i), hello(), i++; for(i=0; i<3; i++) { for(j=0; j<3; j++) { printf("a[%d][%d] = %d\n", i, j, a[i][j]); } } return 0;}
一行代码实现strlen
#include <stdio.h>#include <assert.h>int strlen(const char* s){ return assert(s), (*s ? strlen(s + 1) + 1 : 0);}int main(){ printf("len = %d\n", strlen("Delphi")); printf("len = %d\n", strlen(NULL)); return 0;}
2 小结
- 逗号表达式按照从左向右的顺序计算每个子表达式的值。
- 逗号表达式的值为最后一个子表达式的值。
阅读全文
0 0
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- 逗号表达式
- tfrecord 格式理解
- linux+nginx+express+mongoose+webpack+react+react-router+sass构建web应用
- 斯坦福大学公开课IOS 7 学习笔记(2)
- SpringBoot鸡汤(各个注解集合一)
- 1646
- 逗号表达式
- C++plus笔记7
- 如何将自己应用替换tomcat自带应用
- LightOJ
- 相关接口
- CyclicBarrier源码分析
- jQuery实战学习之点击显示和隐藏
- JAVA 函数 随机生成经纬度
- Javaweb零基础开发(一) Struts配置