in reply to Mixing OR with conditional operator

Speaking generally, there are always three issues:
  1. Operator precedence: In algebra, 1 + 2 * 3 is always 7, not 6.
  2. Bitwise operators: Does, say, "&&" mean "logical and" or "bitwise and?" Is 7 && 16 ... true, or integer 0?
  3. Short-circuiting: The computer stops evaluating a logical expression that is joined by "and" and "or" operators as soon as possible. If you are counting on "side effects" from the entire expression, some of them might not happen.
  • Comment on Re: Mixing OR with conditional operator

Replies are listed 'Best First'.
Re^2: Mixing OR with conditional operator
by Anonymous Monk on Nov 20, 2017 at 14:41 UTC
    In algebra, 1 + 2 * 3 is always 7, not 6.

    in what world would it ever be 6?

      in a world where you stand on your head   ,-)
      (and have different precedences, of course)
      I'm sure that was supposed to be "9" but the point is made. Anyhow, "parentheses are your bestest friend," and so is splitting a complicated expression into several smaller ones using temporary local variables. Write the source-code so that people can understand it at a glance. Compilers and interpreters can take care of themselves. Troubles begin when people mis-read what is put in front of them.