代码片段:
void fn(){
if(14-2==0^2){
cout<<"14-2 is "<<14-2<<"\n";
cout<<"0^2 is "<<(0^2)<<"\n"; //cout<<0^2 shows error: invalid operands of types 'int' and 'const char [2]' to binary 'operator<<'
cout<<"How is if evaluated to be true?";
}
else{
cout<<"else";
}
}输出:
14-2是12
0^2等于2
如果求值为真,如何计算?
我将0^2括在()内,从而解决了这个问题,因此如果条件变为
if(14-2==(0^2))现在这一切都是按预期进行的。
问题:我想知道为什么如果评估是正确的
发布于 2021-08-02 13:57:38
https://stackoverflow.com/questions/68622804
复制相似问题