int x = 5;
if (x < 10)
printf("Hello");
else
printf("World");
a) Hello
b) World
c) HelloWorld
d) No output
In a nested if statement, which else is executed if multiple if statements exist?
a) The first else
b) The last else
c) The nearest if without an else
d) None of the above
What will be the output of the following code?
int x = 5, y = 8;
if (x < 10)
if (y > 10)
printf("A");
else
printf("B");
a) A
b) B
c) No output
d) Error
Switch Case Statements
Which keyword is used to end a switch statement in C?
a) break
b) end
c) exit
d) return
What will happen if the break statement is omitted in a switch case?
a) Only that case executes
b) Compiler error
c) All subsequent cases execute
d) The switch ends
Which of the following types cannot be used in a switch expression?
a) int
b) char
c) float
d) enum
What is the purpose of the default case in a switch statement?
a) To handle all cases
b) To execute if no other case matches
c) To end the switch
d) Optional for all switches
What is the output of the following code?c int x = 2; switch (x) { case 1: printf("One"); case 2: printf("Two"); case 3: printf("Three"); default: printf("Default"); }
a) Two
b) TwoThreeDefault
c) Three
d) Default
Loops (for, while, do-while)
Which loop executes at least once, regardless of the condition?
a) for
b) while
c) do-while
d) if
What is the output of the following code?int i = 0; while (i < 3) { printf("%d", i); i++; }
a) 012
b) 123
c) 0123
d) Error
Which keyword is used to skip an iteration in a loop?
a) skip
b) continue
c) break
d) return
How many times will the following code print “Hello”?for (int i = 0; i < 3; i++) { printf("Hello"); }
a) 1
b) 2
c) 3
d) Infinite
Which loop is most suitable if the number of iterations is known?
a) while
b) for
c) do-while
d) if
Break and Continue
What does the break statement do?
a) Stops the loop immediately
b) Skips to the next iteration
c) Ends the program
d) Nothing
What is the output of the following code?for (int i = 0; i < 5; i++) { if (i == 2) break; printf("%d", i); }
a) 01234
b) 01
c) 012
d) Error
What does the continue statement do?
a) Ends the loop
b) Skips the current iteration and continues with the next one
c) Exits the program
d) None of the above
What is the output of the following code?for (int i = 0; i < 3; i++) { if (i == 1) continue; printf("%d", i); }
a) 01
b) 02
c) 012
d) 1
Which statement cannot be used outside loops?
a) break
b) continue
c) return
d) printf
Goto and Labels
Which statement allows jumping to a label in C?
a) goto
b) jump
c) continue
d) exit
What is a major drawback of using goto statements?
a) Code readability decreases
b) Execution speed decreases
c) Increases complexity
d) Both a and c
What is the output of the following code?int x = 0; label: printf("%d", x); x++; if (x < 3) goto label;
a) 012
b) 123
c) 01
d) 0
Which keyword is used to mark a label?
a) :
b) ;
c) ->
d) .
When should goto be used in C programming?
a) To improve efficiency
b) To avoid deep nesting of code
c) To jump to another function
d) None of the above
Which statement correctly represents the syntax of an if-else block?
a) if (condition) { statement1; } else { statement2; }
b) if (condition) statement1; else statement2;
c) if condition statement1; else statement2;
d) if (condition) statement1; else { statement2; }
What is the primary purpose of the if statement in C?
a) To perform repetitive tasks
b) To check a condition and execute a block of code if it’s true
c) To allow multiple conditions
d) To end the program
In C, what will the else if ladder help achieve?
a) Test multiple conditions in sequence
b) Create a loop
c) Ignore conditional statements
d) Execute code only once
What is printed by the following code?int x = 10; if (x == 10) printf("A"); else if (x > 5) printf("B"); else printf("C");
a) A
b) B
c) C
d) No output
What will happen if there is no else statement in an if-else construct?
a) Code will not compile
b) The else statement is optional
c) Syntax error
d) Compiler warning
Switch Case Statements (continued)
What will be the output of the following code?int x = 3; switch (x) { case 1: printf("One"); break; case 2: printf("Two"); break; case 3: printf("Three"); break; default: printf("Default"); }
a) Default
b) One
c) Three
d) Error
Which case in the switch statement will execute if no match is found?
a) The first case
b) None
c) The last case
d) The default case
What will be the output of the following code if x = 4?switch (x) { case 3: printf("Three"); break; case 4: printf("Four"); break; default: printf("Default"); }
a) Four
b) Default
c) Three
d) Error
Can float be used as an expression in switch statement?
a) Yes
b) No
c) Only with default
d) None of the above
In a switch case, which statement is required to prevent fall-through behavior?
a) continue
b) break
c) exit
d) None
Loops (continued)
Which loop is known as the entry-controlled loop?
a) for
b) while
c) do-while
d) goto
What is the output of the following code?int i = 1; do { printf("%d", i); i++; } while(i < 4);
a) 1
b) 12
c) 123
d) Error
Which loop is known as an exit-controlled loop?
a) for
b) while
c) do-while
d) None of the above
Which loop is best for situations when the condition must be checked before entering the loop?
a) for
b) while
c) do-while
d) goto
How many times will the following code print “Hi”? c for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { printf("Hi"); } }
a) 2
b) 4
c) 6
d) 8
Break and Continue (continued)
What is the output of the following code?int i = 0; while (i < 5) { i++; if (i == 3) continue; printf("%d", i); }
a) 12345
b) 1245
c) 12
d) Error
In which scenarios is the break statement commonly used?
a) Loops
b) switch statements
c) if statements
d) Both a and b
Which keyword forces the loop to terminate the current iteration and continue with the next one?
a) break
b) continue
c) exit
d) jump
Which will execute only once for each pass of the loop?
a) break
b) continue
c) default
d) None
Which loop structure will repeat until i becomes 5? c int i = 0; while (i < 5) { i++; }
a) for loop
b) while loop
c) do-while loop
d) None
Goto and Labels (continued)
Which statement is a direct jump to another point in the code?
a) break
b) continue
c) goto
d) exit
What is printed by the following code?int x = 0; label1: printf("%d", x); x++; if (x < 3) goto label1;
a) 123
b) 012
c) 01
d) 0
How does the use of goto generally affect program readability?
a) Improves readability
b) Makes the program complex and hard to read
c) Makes debugging easier
d) None of the above
When can goto be useful?
a) In structured programming
b) To avoid deeply nested conditions
c) In modern coding practices
d) Both a and c
What is the recommended approach to using goto?
a) Use it frequently for efficiency
b) Avoid it whenever possible
c) Use only for specific situations
d) Never use it
Answer Key Table for Chapter 4: Control Statements