AllInfoHub Logo

AllInfoHub – MCQ Practice

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

  1. 25. Can you have an 'if' statement without an 'else' statement?

    • A. Yes
    • B. No
    • C. Only in certain conditions
    • D. It depends on the compiler
  2. 26. Can you have multiple 'else if' statements after a single 'if' statement?

    • A. Yes
    • B. No
    • C. Only one
    • D. It depends on the compiler
  3. 27. What is the purpose of the '!' operator when used in an 'if' condition?

    • A. Logical AND
    • B. Logical OR
    • C. Logical NOT
    • D. Bitwise NOT
  4. 28. What will be the output of the following code? `int x = 0; if (x) { printf(\True\"); } else { printf(\""False\""); }`"""

    • A. TRUE
    • B. FALSE
    • C. Error
    • D. 0
  5. 29. What will be the output of the following code? `int x = -5; if (x) { printf(\True\"); } else { printf(\""False\""); }`"""

    • A. TRUE
    • B. FALSE
    • C. Error
    • D. -5
  6. 30. Can the 'case' values in a 'switch' statement be of 'char' data type?

    • A. Yes
    • B. No
    • C. Only if type cast
    • D. It depends on the compiler
  7. 31. What happens if the 'default' case is not the last case in a 'switch' statement?

    • A. It will be executed only if no other case matches
    • B. It will be executed first
    • C. It will cause an error
    • D. Its position doesn't matter logically
  8. 32. What is the output of the following code? `int a = 10, b = 5; if (a > b) printf(\A is greater\");`"""

    • A. A is greater
    • B. B is greater
    • C. No output
    • D. Error
  9. 33. What is the output of the following code? `int a = 5, b = 10; if (a > b) printf(\A\"); else printf(\""B\"");`"""

    • A. A
    • B. B
    • C. AB
    • D. No output
  10. 34. What is the output of the following code? `int val = 2; switch (val) { case 1: printf(\One\"); break; case 2: printf(\""Two\""); break; case 2: printf(\""Second Two\""); break; default: printf(\""Other\""); }`"""

    • A. One
    • B. Two
    • C. Second Two
    • D. Other
  11. 35. Are 'break' statements optional in every 'case' of a 'switch' statement?

    • A. Yes
    • B. No
    • C. Only for the 'default' case
    • D. Only for the last case
  12. 36. What will be the output of the following code? `int num = 0; if (num == 0) printf(\Zero\"); else printf(\""Non-zero\"");`"""

    • A. Zero
    • B. Non-zero
    • C. Error
    • D. 0