逻辑与、或运算时的注意点

  • 逻辑与(&&)的优先级高于逻辑或(||)
  • 逻辑与运算一侧数值为0时不再进行后续计算;
  • 逻辑或运算一侧数值为1时不再进行后续计算;
#include<stdio.h>

int main()
{
    
    
	int a = 0, b = -1;
	printf("%d %d %d", a++ && b++, a, b); //输出结果:0 1 -1
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Genius_bin/article/details/112313147
今日推荐