#include <iostream>main()
{
int n;
int a=0x1f;
if (n&a==a)
{
cout<<n;
}
}結果是575,哪位能否說明一下575是如何得來的?如果給n賦初值﹐則結果沒有任何輸出?在 C/C++ C++ / 面向对象问题 版沒有得到滿意答案﹕
http://community.csdn.net/Expert/topic/3166/3166137.xml?temp=.1276056
{
int n;
int a=0x1f;
if (n&a==a)
{
cout<<n;
}
}結果是575,哪位能否說明一下575是如何得來的?如果給n賦初值﹐則結果沒有任何輸出?在 C/C++ C++ / 面向对象问题 版沒有得到滿意答案﹕
http://community.csdn.net/Expert/topic/3166/3166137.xml?temp=.1276056
解决方案 »
- 为什么《WINDOWS网络编程技术》的配套源码中程序先WSARecv( )?
- 某专用IM“回帖哨兵”功能测试贴(release 2)
- ado 方式,_RecordsetPtr的Close() 异常
- 设置主菜单的单选按钮状态,但不是在点击菜单的时候改变状态,而在其他地方控制某项菜单选中与未选中
- 一个进程被创建或销毁的时候,如何得到进程被创建或销毁这一消息及相关信息?
- 急问!MFC用ACTIVEX控件的问题!
- dll的插件模式的问题(菜鸟求帮助)
- adobe acrobat reader这个软件是做什么的,阅读?图片处理?
- 请教高手,高分
- 在WORD下排版时其字体下拉列框中的字体没有了(只有一个很奇怪的字体),知道的或有过类似经历的朋友请进来发个言,谢谢!
- 那位有显示三维离散点的程序(急用)
- socket中数据报连接问题?
if (n&a==a)//检查n的低5位是否全为1.
n未赋值的情况下初值是几要看编译器是如何实现的了.严谨的编译器会按C标准置初值0,但更多的情况下会是随机数或某个特定的便于编译器进行内存访问检查的特定值.
#include <iostream>
using namespace std;你能编译成功么?你想要完成什么功能???你的n没有初始化 是一个随机值
n也可能恰好是 575 然后得到输出 结果575....
0x1f- 〉 0000,0001,1111
与了以后 0001,1111
等于a所以进入if输出n
你没有给n初始化,n应该是个随机数,可能恰好为575,然后按位与后还相等,所以就输出了。
如果你初始化n=63估计也应该输出63。你试验试验,看看是不是。
C++没规定,但C规定的了...
我在其他電腦上也編譯運行過﹐結果都是575,
我用VC6.0
#include <iostream.h>void main()
{
int n=95;
int a=0x1f;
if (n&a==a)
{
cout<<n;
}
}
结果是95
如果后五位不是1,没有打印
==的优先级比&高!还有,讨论int n;n不赋值的这种情况没有任何意义,各种编译器可能对这个值做不同处理。
如果给n赋值,应该只要n的末位为1就能输出。(vs2003)
以下是运算符的优先级,再熟悉一下吧!!!
Table D.1. C++ Operator Precedence and Associativity Precedence Operator Assoc. Meaning
1 :: Scope resolution operator
(expression) Grouping
2 () L–R Function call
() Value construction, that is, type (expr)
[] Array subscript
-> Indirect membership operator
. Direct membership operator
const_cast Specialized type cast
dynamic_cast Specialized type cast
reinterpret_cast Specialized type cast
static_cast Specialized type cast
typeid Type identification
++ Increment operator, postfix
-- Decrement operator, postfix
3 (all unary) ! R–L Logical negation
~ Bitwise negation
+ Unary plus (positive sign)
- Unary minus (negative sign)
++ Increment operator, prefix
-- Decrement operator, prefix
& Address
* Dereference (indirect value)
() Type cast, that is, (type) expr
sizeof Size in bytes
new Dynamically allocate storage
new [] Dynamically allocate array
delete Dynamically free storage
delete [] Dynamically free array
4 .* L–R Member dereference
->* Indirect member dereference
5 (all binary) * L–R Multiply
/ Divide
^ Modulus (remainder)
6 (all binary) + L–R Addition
- Subtraction
7 << L–R Left shift
>> Right shift
8 < L–R Less than
<= Less than or equal to
>= Greater than or equal to
> Greater than
9 == L–R Equal to
!= Not equal to
10 (binary) & L–R Bitwise AND
11 ^ L–R Bitwise XOR (exclusive OR)
12 | L–R Bitwise OR
13 && L–R Logical AND
14 || L–R Logical OR
15 = R–L Simple assignment
*= Multiply and assign
/= Divide and assign
%= Take remainder and assign
+= Add and assign
-= Subtract and assign
&= Bitwise AND and assign
^= Bitwise XOR and assign
|= Bitwise OR and assign
<<= Left shift and assign
>>= Right shift and assign
16 :? R–L Conditional
17 throw L–R Throw exception
18 , L–R Combine two expressions into one