I am having trouble understanding why the following code:
0 || -1
Evaluates to 1? More specifically, I am confused as to what the || and && operators mean when applied to integers.
I am having trouble understanding why the following code:
0 || -1
Evaluates to 1? More specifically, I am confused as to what the || and && operators mean when applied to integers.
Every expression value != 0 evaluates to 1, if value is not equal to zero. (see comment from @MiCo and @M.M.)
|| is an or operation with two operands. If the left or the right operand is not zero the or operation evaluates to 1.
Since -1 is not 0 it evaluates to 1,