Possible Duplicates:
Stupid Question Regarding If-Else's Simultaneous Execution in C++ or C
Is it possble to execute both if and else part of an if — else control statement ?
Hello everyone.. I had a question in an interview like this which i couldn't answer. Consider Following code block. Assume necessary header files.
if(.......)
{
printf("hello");
}
else
{
printf("world");
}
without moving/adding any code & without use of additional printing statements bring output as "Hello world"..You have to write the missing condition in if statement.. is it possible to execute both blocks by some condition?? Please help
Use two if statements if both if statement conditions could be true at the same time. In this example, both conditions can be true. You can pass and do great at the same time. Use an if/else statement if the two conditions are mutually exclusive meaning if one condition is true the other condition must be false.
No, that is not possible (inside the same process).
The logical AND (&&) operator and if...else statements in JavaScript. In the logical AND ( && ) operator, if both conditions are true , then the if block will be executed. If one or both of the conditions are false , then the else block will be executed.
This will work
if(schrodingers_cat_is_dead())
{
printf("hello");
}
else
{
printf("world");
}
Unfortunately, as soon as you look at the output, not only will it collapse into the state of only producing "hello" or "world", but there's a 50% chance you will have murdered a cat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With