AllInfoHub Logo

AllInfoHub – MCQ Practice

Control Flow (if else switch) – Multiple Choice Questions (MCQs)

  1. 13. What will be the output of the following code? `int x = 5; if (x < 3) { printf(\A\"); } else if (x > 4) { printf(\""B\""); } else { printf(\""C\""); }`"""

    • A. A
    • B. B
    • C. C
    • D. Error
  2. 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\""); }`"""

    • A. One
    • B. Three
    • C. Other
    • D. No output
  3. 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\""); }`"""

    • A. One
    • B. Two
    • C. Three
    • D. OneTwoThree
  4. 16. What happens if you don't use 'break' in a 'switch' case?

    • A. The program exits
    • B. The loop terminates
    • C. Execution falls through to the next case
    • D. An error occurs
  5. 17. Can the expression in a 'switch' statement be a floating-point number?

    • A. Yes
    • B. No
    • C. Only if it's an integer type cast
    • D. It depends on the compiler
  6. 18. Can the 'case' values in a 'switch' statement be variables?

    • A. Yes
    • B. No
    • C. Only if they are constants
    • D. It depends on the data type
  7. 19. Is the 'default' case in a 'switch' statement mandatory?

    • A. Yes
    • B. No
    • C. Only if there are no matching cases
    • D. It's good practice but not mandatory
  8. 20. What is the equivalent of a simple if-else statement using the ternary operator?

    • A. loop
    • B. switch
    • C. conditional expression
    • D. function call
  9. 21. Rewrite the following if-else statement using the ternary operator: `if (a > b) { max = a; } else { max = b; }`

    • A. `max = (a > b) ? a : b;`
    • B. `(a > b) ? max = a : max = b;`
    • C. `max = if (a > b) a else b;`
    • D. `if (a > b) max = a else max = b;`
  10. 22. What will be the output of the following code? `int age = 17; if (age >= 18) { printf(\Adult\"); } else { printf(\""Minor\""); }`"""

    • A. Adult
    • B. Minor
    • C. Error
    • D. 17
  11. 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\""); }`"""

    • A. A
    • B. B
    • C. C
    • D. Error
  12. 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(\""?\""); }`"""

    • A. Mon
    • B. Thu
    • C. ?
    • D. No output