AllInfoHub Logo

AllInfoHub – MCQ Practice

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

  1. 1. Which keyword is used to start an if statement in C?

    • A. if
    • B. then
    • C. switch
    • D. case
  2. 2. Which keyword is used to specify a block of code to be executed if the if condition is false?

    • A. else if
    • B. elseif
    • C. else
    • D. otherwise
  3. 3. Which keyword is used to check multiple conditions sequentially in an if-else structure?

    • A. else
    • B. elseif
    • C. switch
    • D. case
  4. 4. What is the purpose of the 'switch' statement in C?

    • A. To loop through a block of code
    • B. To define a function
    • C. To execute different blocks of code based on the value of an expression
    • D. To declare a variable
  5. 5. Which keyword is used to define different cases within a 'switch' statement?

    • A. default
    • B. otherwise
    • C. case
    • D. option
  6. 6. What happens if none of the 'case' values match the expression in a 'switch' statement?

    • A. The program terminates
    • B. The 'if' block is executed
    • C. The 'default' block is executed (if present)
    • D. Nothing happens
  7. 7. Which keyword is used to specify a default block of code in a 'switch' statement?

    • A. default
    • B. else
    • C. otherwise
    • D. none
  8. 8. What is the purpose of the 'break' statement within a 'switch' case?

    • A. To exit the program
    • B. To skip the next iteration of a loop
    • C. To exit the 'switch' statement
    • D. To continue to the next case
  9. 9. Can you have nested if-else statements in C?

    • A. Yes
    • B. No
    • C. Only up to a certain level
    • D. It depends on the compiler
  10. 10. What is the condition in an 'if' statement enclosed in?

    • A. Square brackets []
    • B. Curly braces {}
    • C. Parentheses ()
    • D. Angle brackets <>
  11. 11. What will be the output of the following code? `int x = 5; if (x > 3) { printf(\Hello\"); }`"""

    • A. Hello
    • B. No output
    • C. Error
    • D. 5
  12. 12. What will be the output of the following code? `int x = 2; if (x > 3) { printf(\Hello\"); } else { printf(\""World\""); }`"""

    • A. Hello
    • B. World
    • C. Error
    • D. 2