AllInfoHub Logo

AllInfoHub – MCQ Practice

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

  1. 37. What will be the output of the following code? `int temp = 30; if (temp < 20) printf(\Cold\"); else if (temp > 25) printf(\""Warm\""); else printf(\""Moderate\"");`"""

    • A. Cold
    • B. Warm
    • C. Moderate
    • D. Error
  2. 38. What will be the output of the following code? `int choice = 'B'; switch (choice) { case 'A': printf(\Apple\"); break; case 'B': printf(\""Banana\""); break; default: printf(\""Fruit?\""); }`"""

    • A. Apple
    • B. Banana
    • C. Fruit?
    • D. Error
  3. 39. Can you use relational operators in the 'case' conditions of a 'switch' statement?

    • A. Yes
    • B. No
    • C. Only with constants
    • D. It depends on the compiler
  4. 40. What is the purpose of the 'if' statement?

    • A. To define a loop
    • B. To declare variables
    • C. To execute a block of code conditionally
    • D. To define a function
  5. 41. What is the purpose of the 'else' statement?

    • A. To execute a block of code if the 'if' condition is true
    • B. To terminate the program
    • C. To execute a block of code if the 'if' condition is false
    • D. To define a new case in a switch
  6. 42. What is the purpose of the 'else if' statement?

    • A. To define the first condition
    • B. To define the last condition
    • C. To check multiple conditions in sequence
    • D. To define a default case
  7. 43. What is the output of the following code? `int value = 1; if (value--) printf(\True\"); else printf(\""False\"");`"""

    • A. TRUE
    • B. FALSE
    • C. Error
    • D. 0
  8. 44. What is the output of the following code? `int value = 0; if (value--) printf(\True\"); else printf(\""False\"");`"""

    • A. TRUE
    • B. FALSE
    • C. Error
    • D. -1
  9. 45. What is the output of the following code? `int count = 5; if (++count > 5) printf(\Greater\"); else printf(\""Smaller\"");`"""

    • A. Greater
    • B. Smaller
    • C. Error
    • D. 6
  10. 46. What is the output of the following code? `int count = 5; if (count++ > 5) printf(\Greater\"); else printf(\""Smaller\"");`"""

    • A. Greater
    • B. Smaller
    • C. Error
    • D. 6
  11. 47. Can you use logical operators within the condition of an 'if' statement?

    • A. Yes
    • B. No
    • C. Only AND
    • D. Only OR
  12. 48. Can you use assignment operators within the condition of an 'if' statement?

    • A. Yes
    • B. But it's generally not recommended
    • C. No
    • D. Only with integers