Oct 18, 2015 at 12:11am
1 2 3 4 5 6 7
|
bool x = false;
if(!x){
x = true;
}else{
printf("Hello!");
}
|
Shouldn't this program print "Hello!"?
This works fine,
1 2 3 4 5 6 7 8
|
bool x = false;
if(!x){
x = true;
}
if(x){
printf("Hello!");
}
|
Why does first code not working?
Last edited on Oct 18, 2015 at 12:11am
Oct 18, 2015 at 12:14am
because if it matches the condition in the first statement it will skip the else statement completely because x is false.
Oct 18, 2015 at 12:31am
So that means if first condition works, it skips all rest conditions?