Simultaneous execution of both if and else blocks

In C or C++

if ( x )
    statement1;
else
    statement2;

For what value of x will both statements be executed?

I know we can execute if-else together like this:

if(1){
    goto ELSE;
}
else{
    ELSE:
}

Is there any way, like a value? (Which I think is not possible. Asking because someone is arguing!)

Answer

for what value of x both statements will be executed?

There is no such value: either the value evaluates to true (something != 0), or it evaluates to false) (0). No other possible values exist.

I know we can execute if-else together like this: if(1){ goto ELSE; } else{ ELSE: }

That works but it isn’t depending of the value of the if condition at all.

Leave a Reply

Your email address will not be published. Required fields are marked *