Control Flow (if else switch) – Multiple Choice Questions (MCQs)
-
-
14. What will be the output of the following code? `int x = 3; switch (x) { case 1: printf(\One\"); break; case 3: printf(\""Three\""); break; default: printf(\""Other\""); }`"""
-
15. What will be the output of the following code? `int x = 2; switch (x) { case 1: printf(\One\"); case 2: printf(\""Two\""); case 3: printf(\""Three\""); }`"""
-
16. What happens if you don't use 'break' in a 'switch' case?
-
17. Can the expression in a 'switch' statement be a floating-point number?
-
18. Can the 'case' values in a 'switch' statement be variables?
-
19. Is the 'default' case in a 'switch' statement mandatory?
-
20. What is the equivalent of a simple if-else statement using the ternary operator?
-
21. Rewrite the following if-else statement using the ternary operator: `if (a > b) { max = a; } else { max = b; }`
-
22. What will be the output of the following code? `int age = 17; if (age >= 18) { printf(\Adult\"); } else { printf(\""Minor\""); }`"""
-
23. What will be the output of the following code? `int grade = 95; if (grade >= 90) { printf(\A\"); } else if (grade >= 80) { printf(\""B\""); } else { printf(\""C\""); }`"""
-
24. What will be the output of the following code? `int day = 4; switch (day) { case 1: printf(\Mon\"); break; case 4: printf(\""Thu\""); break; default: printf(\""?\""); }`"""