【发布时间】:2014-04-06 21:09:50
【问题描述】:
无法使用 Visual Studio 2010 直接进行这个简单的计算
std::cout<<(1 | 1 & 2);
//gives the value 1, was expecting 2 since 1 | 1 = 2 , the & 2 gives 2
std::cout<<( (1 | 1) & 2);
//gives the value 0, why is this different from above?
【问题讨论】:
-
1|1 不等于 2。这不是算术
-
请查看运算符优先级。欢迎使用 StackOverflow。
-
@ScottMcP-MVP:当然是算术。但这不是加法,即使某些包含或的符号使用
+符号。
标签: c++ c visual-c++