What is the result from executing this code snippet?

Advertisement

bool x=true, y=false;
if(~x || y){
/*part A*/
}
else{
/*part B*/
}

  • Part A executes because the expression (~x || y) always results in true if y==false.
  • Part B executes because the statement (~x || y) is invalid, thus false.
  • Part A executes because ~x is not zero, meaning true.
  • Part B executes because ~x is false and y is false, thus the OR operation evaluates as false.
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Leave a Comment

Share via
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.