If A
is false, then A && B
is false, so there is no need to check B
. So very often, the compiler writes assembly in such a way that if A && B
is to be evaluated and A
is evaluated as false, then B
is not evaluated.
Can I assume that that all compilers which adhere to ISO standard (let's say C99 or more modern), will behave like this?
The reason I ask is that in my program, I have the statement if (i > -1 && x[i] > 3)
. So if i
is negative but x[i] > 3
still gets evaluated, this will lead to a segmentation fault.