(8)-逻辑符号间的逻辑

代码

#include <stdio.h>
int main()
{
  int a=0,b=0;

  printf("%d
",!a||++b||b++);
  printf("b=%d
",b);
  printf("%d
",!a&&++b&&b++);
  printf("b=%d
",b);

  return 0;
}

:以上输出什么,为什么?

解答:int a=0,b=0;在在第一次printf语句中,!a为1,后面的++b和b++就不做了,所以第二次输出是0,第三次printf中是与运算,后面的++b和b++还要做的,所以第二次会输出b=2。

======= welcome to my HomePage(http://blog.csdn.net/zhanxinhang) to have a communication =======

文章导航