Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 布尔方程_C++_Boolean Logic - Fatal编程技术网

C++ 布尔方程

C++ 布尔方程,c++,boolean-logic,C++,Boolean Logic,为什么这段代码有两个不同的输出GCC 4.5.1我已经评论了重要的几行: int main() { bool a = 1; bool b = 1; bool c = 1; bool a_or_b = (a || b); bool not_a_or_b = !a_or_b; bool not_a_or_b__c = not_a_or_b || c; cout << "(a || b): " << (a || b) &l

为什么这段代码有两个不同的输出GCC 4.5.1我已经评论了重要的几行:

int main()
{
    bool a = 1;
    bool b = 1;
    bool c = 1;
    bool a_or_b = (a || b);
    bool not_a_or_b = !a_or_b;
    bool not_a_or_b__c = not_a_or_b || c;
    cout << "(a || b): " << (a || b) << '\n';
    cout << "!(a || b): " << !(a || b) << '\n';
    cout << "!(a || b) || c: " << (!(a || b)) || c << '\n';//HERE I'M GETTING 0 (incorrectly I would say)
    cout << "bool vars:\n";//WHY THIS LINE IS PRINTED AFTER THE PREVIOUS LINE BUT NOT BELOW IT?
    cout << "(a || b): " << a_or_b << '\n';
    cout << "!(a || b): " << not_a_or_b << '\n';
    cout << "!(a || b) || c: " << not_a_or_b__c << '\n';//HERE I'M GETTING 1
    return 0;
}
这是因为这是因为更改此部分:

<< (!(a || b)) || c << '\n'; //interpreted as (!(a || b)) || (c << '\n')
为此:

((!(a || b)) || c) << '\n'; //interpreted as intended!
更改此部分:

<< (!(a || b)) || c << '\n'; //interpreted as (!(a || b)) || (c << '\n')
为此:

((!(a || b)) || c) << '\n'; //interpreted as intended!
它解释

(!(a || b)) || c << '\n'
作为

它解释

(!(a || b)) || c << '\n'
作为

这是夹具问题吗

你用!a | | | b | | c第一部分肯定是0,也许口译员甚至不看| | c部分。

这是一个钳夹问题吗


你用!第一部分为0,当然解释器甚至不看C部分。

对于逻辑或,编译的代码通常不解释C++,如果第一个操作数是false,必须考虑第二个操作数。只有第一个操作数为真时,第二个操作数才会被评估。对于逻辑或,编译的代码通常不解释C++,如果第一个操作数是false,则必须考虑第二个操作数。只有当第一个操作数为真时,第二个操作数才不能计算。实际上它解释为cout,当然,c实际上解释为cout,当然,c