3.1.1 - If and If Else Statment.
1. What is the purpose of an "if" statement in a program?
Correct Answer: (B) To take a decision based on a condition
2. Which of the following is a correct syntax for an "if" statement?
Correct Answer: (C) if (condition) { statement; }
3. Which of the following is a valid relational operator used in decision statements?
Correct Answer: (C) ==
4. What will happen if the condition in an "if" statement evaluates to false?
Correct Answer: (C) The "else" block will execute (if it exists)
5. Which logical operator is used to check if both conditions are true?
Correct Answer: (B) &&
6. Which of the following is an example of an "if-else" statement?
Correct Answer: (A) if (condition) { statement; } else { statement; }
7. What will the following code output if the user enters 150?
#include
void main() {
int no;
printf("enter a no");
scanf("%d", &no);
if(no > 100) {
printf("No is >100 ");
printf("\n %d", no);
}
printf("\n End of program");
}
Correct Answer: (A) No is >100 150
8. What is the output of the following code if the user enters 3?
#include
void main() {
int no;
printf("enter a no");
scanf("%d", &no);
if(no % 2 == 0) {
printf("No is Even ");
} else {
printf("No is Odd ");
}
printf("\n End of program");
}
Correct Answer: (C) No is Odd End of program
9. Which statement can be used to check multiple conditions in a decision-making process?
Correct Answer: (A) if...else if...else
10. In a decision statement, what is the purpose of the else block?
Correct Answer: (B) To execute if the condition is false
11. Which of the following is a logical operator used in decision statements?
Correct Answer: (C) &&
12. What is the significance of parentheses () in an "if" condition?
Correct Answer: (B) They contain the condition that will be evaluated
13. What keyword is used to introduce an alternative condition in decision-making statements?
Correct Answer: (A) else
14. Which relational operator checks if two values are not equal?
Correct Answer: (A) !=
15. What kind of decision-making structure allows for multiple "if" statements one after another?
Correct Answer: (B) Else if ladder