#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

解决方案 »

  1.   

    int a=0x1F;
    if (n&a==a)//检查n的低5位是否全为1.
    n未赋值的情况下初值是几要看编译器是如何实现的了.严谨的编译器会按C标准置初值0,但更多的情况下会是随机数或某个特定的便于编译器进行内存访问检查的特定值.
      

  2.   

    #include <iostream>->
    #include <iostream>
    using namespace std;你能编译成功么?你想要完成什么功能???你的n没有初始化 是一个随机值
    n也可能恰好是 575 然后得到输出 结果575....
      

  3.   

    575 - 〉 0010,0011,1111
    0x1f- 〉 0000,0001,1111
    与了以后       0001,1111 
    等于a所以进入if输出n     
    你没有给n初始化,n应该是个随机数,可能恰好为575,然后按位与后还相等,所以就输出了。
    如果你初始化n=63估计也应该输出63。你试验试验,看看是不是。
      

  4.   

    SatanLi1982(红魔) :
    C++没规定,但C规定的了...
      

  5.   

    我使用的編譯器是﹕Dev-C++ 4.9.6.0
    我在其他電腦上也編譯運行過﹐結果都是575,
      

  6.   

    你用的什么编译器呀?
    我用VC6.0
    #include <iostream.h>void main()
    {
    int n=95;
    int a=0x1f;
    if (n&a==a)
    {
    cout<<n;
    }
    }
    结果是95
    如果后五位不是1,没有打印
      

  7.   

    上面的答复都错了!if (n&a==a) 等价与 if (n&(a==a))
    ==的优先级比&高!还有,讨论int n;n不赋值的这种情况没有任何意义,各种编译器可能对这个值做不同处理。
      

  8.   

    我用vs2003编译,输出为1
    如果给n赋值,应该只要n的末位为1就能输出。(vs2003)
      

  9.   

    同意shootingstars(有容乃大,无欲则刚) 的解释
    以下是运算符的优先级,再熟悉一下吧!!!
    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