Recall & Review
beginner
What is the purpose of an if–else statement in C?
An if–else statement lets the program choose between two paths: one if a condition is true, and another if it is false.
Click to reveal answer
beginner
Write the basic syntax of an if–else statement in C.
if (condition) {
// code if condition is true
} else {
// code if condition is false
}
Click to reveal answer
beginner
What happens if the condition in an if statement is false and there is no else block?
The program skips the if block and continues with the next code after it, doing nothing inside the if block.
Click to reveal answer
intermediate
Can you have multiple else if blocks in C? What is their purpose?
Yes, multiple else if blocks let you check several conditions one after another, running the code for the first true condition.Click to reveal answer
beginner
Explain with an example how if–else helps in decision making.
Example: if (score >= 50) {
printf("Pass\n");
} else {
printf("Fail\n");
}
This checks if score is 50 or more to print Pass, otherwise prints Fail.
Click to reveal answer
What will the following code print if x = 10?
if (x > 5) {
printf("Yes");
} else {
printf("No");
}
✗ Incorrect
Since 10 is greater than 5, the condition is true, so it prints "Yes".
Which keyword is used to check an additional condition after an if in C?
✗ Incorrect
In C, the correct keyword is "else if" (two words).
What happens if the condition in an if statement is false and there is no else block?
✗ Incorrect
If the condition is false and no else block exists, the program skips the if block and continues.
Which of these is a valid if–else syntax in C?
✗ Incorrect
In C, conditions must be inside parentheses: if (condition) { } else { }
Can an if statement exist without an else block?
✗ Incorrect
The else block is optional; you can have just an if statement.
Explain how an if–else statement controls the flow of a program.
Think about how the program chooses what to do next based on a question.
You got /4 concepts.
Write a simple if–else statement in C that prints "Even" if a number is even, and "Odd" if it is odd.
Use number % 2 to check if remainder is zero.
You got /4 concepts.