环境是在Ubuntus环境下测试的
#include <stdio.h> int main(int argc, char *argv[]) { int x = 5, y = 4, z; //if (x != 5 || y++) { if (x != 5 && y++) {//这点需要特别的注意 z = x + y; printf("true:x=%d, y=%d,z=%d ", x, y, z); } else { z = x - y; printf("false:x=%d, y=%d,z=%d ", x, y, z); } return 0; }
这种情况 =x-5 ,y =4 z=1
#include <stdio.h> int main(int argc, char *argv[]) { int x = 5, y = 4, z; //f (x != 5 || y++) { if( ( y++) &&(x!=5)) { z = x + y; printf("true:x=%d, y=%d,z=%d ", x, y, z); } else { z = x - y; printf("false:x=%d, y=%d,z=%d ", x, y, z); } return 0; }
这种时候 y=5,x=5,z=0;