首页 > 试题广场 >

以下程序输出结果是 ? #include us

[问答题]
以下程序输出结果是 ?

#include <iostream>
using namespace std;
int main()
{
    int x = 2, y, z;
    x *= (y=z=5);
    z = 3;
    x += (y & z);
    x += (y && z);
    cout << x << endl;
    return 0;
}

推荐
12
发表于 2018-02-23 18:03:47 回复(3)
&是位运算,&&用于逻辑与,当y=5,z=3时, y&z就是101&011得到001的值1,y&&z,y和z都不为0,所以值为1,最后得到10+1+1=12
发表于 2018-03-01 09:16:28 回复(0)
2*5+1+1=12
发表于 2018-02-28 23:33:46 回复(0)
x = x * 5 = 2 * 5 = 10;
z = 3;
y = 5;
3 & 5 :
0011
0101
0001

x = 10 + ( 3 & 5 ) = 10 + 1 = 11;
x = 11 + 1 = 12;
发表于 2021-07-25 09:45:25 回复(0)
14
发表于 2018-03-09 14:14:32 回复(0)
int main()
{
    int x = 2, y, z;
    x *= (y=z=5); // 括号内返回5,x = 10  y = 5, z =5;
    z = 3;
    x += (y & z); // x = x + 1 = 11
    x += (y && z); // x = x + 1 = 12
    cout << x << endl;
    return 0;
}
输出12.

发表于 2022-08-05 16:26:25 回复(0)
12
发表于 2022-04-20 15:13:45 回复(0)
12
发表于 2018-05-11 15:17:31 回复(0)
12
发表于 2018-03-23 00:01:01 回复(0)
11
发表于 2018-03-19 22:29:52 回复(0)
2
10
11
15
发表于 2018-03-14 16:06:04 回复(1)
12
发表于 2018-03-13 15:22:43 回复(0)
12
发表于 2018-03-12 22:26:43 回复(0)
12
发表于 2018-03-10 16:15:27 回复(0)
12
发表于 2018-03-07 10:02:51 回复(0)
12
发表于 2018-03-04 22:56:05 回复(0)
11
发表于 2018-02-26 10:09:08 回复(0)
初始:2 正确:12
编辑于 2018-02-25 19:21:56 回复(5)
12
发表于 2018-02-25 16:22:08 回复(0)