b的值是怎么不变的?
How is the value of b unchanged?
b
的值如何保持不变?
#include <iostream>
int main()
{
int a = 5, b = 10;
if (++a || ++b)
std::cout << a << b;
system("PAUSE");
return 0;
}
输出为610
。但如何?
下面是if语句的工作原理:
if(condition1 || condition2 || condition 3){
//do this
}
现在如果condition1为真(在您的代码中,因为a!=0),执行将直接移动到块内,而不检查2和3。
如果你也想增加b,试试&&替换||
相关文章:
- 没有找到相关文章