我在按位'&'运算符中缺少一些基本知识。
5 = 101
4 = 100
因此,为什么以下if
条件的输出为true原因,而bit101 & 100
为假:
#include <stdio.h>
main()
{
if(5&4)
printf("Yes\n");
}
5是101。
4是100。
5 & 4
是不是0:
101
100 &
↓↓↓
100
问题解决了✓
澄清:
在C语言中,每个非零值都满足if
条件。意思是,如果您写:
if (-5) {
if (100) {
// reachable code
}
}
鉴于:
if (0) {
destroyTheWorld(); // we are safe
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句