码迷,mamicode.com
首页 > 其他好文 > 详细

表达式的求值顺序

时间:2014-10-08 02:59:54      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   sp   c   on   代码   r   amp   

代码:

#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


表达式的求值顺序

标签:style   io   ar   sp   c   on   代码   r   amp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!