小编k1g*_*abi的帖子

打印以相反顺序写入的表达式时获得不同的结果

为什么我在第3行得到不同的结果?输出是:

1
1
0
1
Run Code Online (Sandbox Code Playgroud)

我不应该收到行号.3还输出1而不是0?它具有与其他行相同的语法.

#include <iostream>
using namespace std;

int main()
{
    int x = -3;
    bool a = (x % 2 == 1) || (x < 0);
    bool b = (x < 0) || (x % 2 == 1);
    cout << a << "\n";                              // line 1
    cout << b << "\n";                              // line 2
    cout << (x % 2 == 1) || (x < 0); cout << "\n";  // line 3
    cout …
Run Code Online (Sandbox Code Playgroud)

c++ operator-precedence

2
推荐指数
1
解决办法
81
查看次数

标签 统计

c++ ×1

operator-precedence ×1