0

This seems to be trivial but I forget how conditions are treated, if(!a && b) here if a is true then it will check for b also? or it will see the && and stop?

Barry
  • 286,269
  • 29
  • 621
  • 977
Mihai
  • 29
  • 1
  • 7
  • 2
    Are you referring to the logical AND operator(`&&`)? In that case, it will not check `b` if `a` is true. Read about short-circuiting. – Spikatrix Apr 25 '15 at 13:35
  • 1
    @CoolGuy [`and` is the same as `&&`](http://en.cppreference.com/w/cpp/language/operator_alternative). – Emil Laine Apr 25 '15 at 13:36
  • 1
    Damn, was just about to mark it a duplicate of this one: http://stackoverflow.com/questions/628526/is-short-circuiting-boolean-operators-mandated-in-c-c-and-evaluation-order – Barry Apr 25 '15 at 13:37
  • Ok so it seems that `the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated` Thanks – Mihai Apr 25 '15 at 13:42
  • @zenith , I did not know that because I'm not familiar with C++ much. Thanks for the info! – Spikatrix Apr 25 '15 at 13:43
  • So to not open a new question, for this case `if(!(a=b))` firstly a takes b value and then it;s evaluated? For ex if b=0 then that condition will be true right? – Mihai Apr 26 '15 at 11:40

0 Answers0