通过位运算判断奇偶,以节约时间,但结果不是想要的,代码如下:
1 int main() 2 { 3 int a = 10; 4 if(a & 0x1 == 0) cout << "10是偶数 "; 5 else cout << "10是奇数 "; 6 return 0; 7 }
运行结果如下:
修改如下,加上括号。
1 if((a & 0x1 )== 0) cout << "hello ";