In C or C++
if ( x )
statement1;
else
statement2;
For what value of x
will both statements be executed?
I know
Without devious trickery, no, this is not possible. Consider what the expression means:
if (cond) {
ifTrue;
} else {
ifFalse;
}
This says to execute ifTrue
if cond
is true (a non-zero value/true
), and to execute ifFalse
if cond
is false (zero/false
). Since cond
can't be simultaneously true and false, you can't execute both ifTrue
and ifFalse
without a special case, such as goto
.