Skip to main content

Section 9.2 if - else Statements

Next, weโ€™ll see how to perform another action in case the condition is not met.

If you cannot see this codecast, please click here.

Aside: Video Description.

Check Your Understanding Check Your Understanding

1.

What is the output of the following piece of code, assuming that n is a variable of type int that has the value 1:
if (n) printf("You win!");
else printf("Ooops!");
  • You win!
  • Correct
  • Ooops!
  • Not quite - try again!
  • You win! Ooops!
  • Not quite - try again!
  • This does not generate any output.
  • Not quite - try again!
Hint.
Watch out for little details such as the semicolon at the end of the statement or the parentheses surrounding the condition.