Control Structures: If-Else, Loops, Switch MCQs with Answers
Which of the following control structures is used to make a decision based on a condition?
a) If-else
b) For loop
c) While loop
d) Switch case
What does the “else” block in an if-else statement do?
a) Executes if the condition is true
b) Executes if the condition is false
c) Executes only when no other statements are provided
d) Defines the condition
Which of the following is the correct syntax for a switch statement in C?
a) switch(x){ case 1: … break; default: … }
b) switch x: { case 1: … break; }
c) if (x == 1) {…}
d) for switch(x) {…}
What is the purpose of the “break” statement in a switch case?
a) To exit the loop
b) To stop the switch statement and exit
c) To skip the current case
d) To end the function
Which loop structure is used when the number of iterations is known beforehand?
a) While loop
b) Do-while loop
c) For loop
d) Switch statement
Which of the following loops guarantees that the loop body is executed at least once?
a) For loop
b) While loop
c) Do-while loop
d) Switch statement
Which of the following is true about the “if” statement?
a) It always executes a block of code
b) It executes a block of code only if the condition is true
c) It executes the “else” block only
d) It runs indefinitely
Which control structure is used to handle multiple conditions in a decision-making process?
a) If-else
b) Nested loops
c) Switch
d) Continue
Which of the following statements is used to skip the current iteration in a loop and proceed to the next iteration?
a) Break
b) Continue
c) Return
d) Exit
What does the following for-loop do?
for (int i = 0; i < 5; i++) { printf(“%d”, i); }
a) Prints numbers from 1 to 5
b) Prints numbers from 0 to 4
c) Prints numbers from 0 to 5
d) Infinite loop
Which of the following is NOT a valid conditional operator in C?
a) ==
b) >=
c) !=
d) =!
What is the result of the following condition in an if statement: if (5 > 3)?
a) True
b) False
c) Undefined
d) Error
Which of the following loop types requires a condition to be checked after each iteration?
a) For loop
b) While loop
c) Do-while loop
d) Switch statement
What happens when a “break” statement is encountered in a loop?
a) It skips the current iteration
b) It exits the loop immediately
c) It restarts the loop
d) It skips the next iteration
Which statement is used to check multiple conditions in an if-else chain?
a) Else
b) Else if
c) Break
d) Continue
What is the output of the following code?
int i = 0; while (i < 3) { printf(“%d”, i); i++; }
a) 123
b) 012
c) 0
d) Infinite loop
Which statement is used in a loop to exit the loop before the loop condition is false?
a) Exit
b) Break
c) Return
d) Stop
What is the correct syntax for an if-else statement in C?
a) if (condition) { … } else { … }
b) if condition { … } else { … }
c) if (condition) then { … } else { … }
d) if { condition } else { … }
What type of loop would you use to execute a block of code a specific number of times?
a) While loop
b) For loop
c) Do-while loop
d) Switch case
Which of the following is an infinite loop in C?
a) for (int i = 0; i < 10; i++) {}
b) while (1) {}
c) do { } while (10);
d) for (int i = 10; i > 0; i–) {}
What does the “continue” statement do in a loop?
a) Exits the loop
b) Skips to the next iteration of the loop
c) Terminates the program
d) Ends the current function
Which of the following is NOT a valid way to define a switch statement case?
a) case 1:
b) case ‘A’:
c) case true:
d) case 0:
What is the main purpose of the “default” case in a switch statement?
a) To handle all valid cases
b) To handle cases that are not explicitly listed
c) To break out of the switch
d) To initialize variables
What is the time complexity of the following loop?
for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { … } }
a) O(1)
b) O(n)
c) O(n^2)
d) O(n^3)
Which of the following statements is used in a switch-case structure to terminate the case execution?
a) Exit
b) Continue
c) Break
d) Return
What is the primary difference between a while loop and a do-while loop?
a) A while loop checks the condition before executing the loop body, while a do-while loop checks it after
b) A do-while loop never runs
c) A while loop executes at least once
d) A do-while loop does not require a condition
Which of the following is the correct syntax for a “for” loop in C?
a) for (int i = 0; i < 5; i++) {}
b) for (int i = 0; i <= 5; i++)
c) for int i = 0; i < 5; i++
d) for (i = 0; i < 5; i++) {}