首页 > 其他 > 详细

表达式的求值顺序

时间:2014-10-08 01:09:04      阅读:320      评论:0      收藏:0      [点我收藏+]

代码:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

// C语言保证逻辑表达式是从左至右求值

int main(void) {

	// printf("Left") == 4
	// printf("Right") == 5

	if (!printf("Left") && printf("Right")) {
		// ...
	}

	printf("\n");

	if (printf("Left") || !printf("Right")) {
		// ...
	}

	// &&和||运算符是顺序点(Sequence point)
	int x = 0;
	(x++ < 1 && x < 1) == false;

	return EXIT_SUCCESS;
}

输出:

Left
Left


表达式的求值顺序

原文:http://my.oschina.net/Xwoder/blog/324767

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!