search

Home  >  Q&A  >  body text

c++ - Is cout << b || a; equivalent to (cout << b) || a;

bool b = 0;
int a = 2;
cout << b || a;  // 0

bool b = 0;
int a = 2;
cout << (b || a);  // 1
伊谢尔伦伊谢尔伦2737 days ago938

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-24 09:45:01

    << has priority 5, which is higher than ||’s priority 12.

    1   ()  []  .  ->
    2   !  ~   -(负号) ++  --   &(取变量地址)*   (type)(强制类型)    sizeof 
    3   * / %
    4   + - 
    5   >> <<  
    6   > >= < <= 
    7   == !=   
    8   &  
    9   ^   
    10  |   
    11  &&
    12  ||
    13  ?:
    14   =  +=  -=  *=  /=   %=  |=   ^=   &=   >>=   <<=
    15  ,

    reply
    0
  • Cancelreply