Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 351–360 of 490
Topics in C Programming
Q.351 Medium Control Flow
What is the output of this code?
char ch = 'B';
switch(ch) {
case 'A':
case 'B':
case 'C': printf("Vowel");
break;
default: printf("Consonant");
}
A Vowel
B Consonant
C No output
D Compilation error
Correct Answer:  A. Vowel
EXPLANATION

ch='B' matches case 'B', which has no statements. Execution falls through to case 'C' which has no statements, then prints 'Vowel' and breaks.

Test
Q.352 Medium Control Flow
In C programming, what is the difference between break in a loop and break in a switch statement?
A There is no difference
B break in switch exits all nested structures, break in loop exits only the loop
C break in loop exits the loop, break in switch exits only the current case
D break in switch works only with integers, break in loop works with all types
Correct Answer:  C. break in loop exits the loop, break in switch exits only the current case
EXPLANATION

Both break statements exit their immediate enclosing structure. In loops, break exits the loop; in switch, break exits the switch block.

Test
Q.353 Medium Control Flow
Which control structure would be most efficient to validate if a number is within one of several specific values?
A Multiple if-else if chains
B Nested if statements
C switch statement
D do-while loop with break
Correct Answer:  C. switch statement
EXPLANATION

switch statement is optimized for multiple discrete value checks and is more readable than chained if-else statements.

Test
Q.354 Medium Control Flow
What will be the output of this code?
int n = 5;
switch(n) {
case 4: printf("Four");
case 5: printf("Five");
case 6: printf("Six");
break;
default: printf("Other");
}
A Five
B FiveSix
C FourFiveSix
D Other
Correct Answer:  B. FiveSix
EXPLANATION

n=5 matches case 5. Without break, it falls through to case 6 before encountering break. Prints 'FiveSix'.

Test
Q.355 Medium Control Flow
How many times will the loop execute?
int i = 0;
while(i++ < 5) {
printf("%d ", i);
}
A 4 times
B 5 times
C 6 times
D Infinite loop
Correct Answer:  B. 5 times
EXPLANATION

i++ returns value before incrementing. Condition checks: 0<5(T), 1<5(T), 2<5(T), 3<5(T), 4<5(T), 5<5(F). Loop runs 5 times.

Test
Q.356 Medium Control Flow
What will this code output?
for(int i = 1; i
A 1\n12\n123
B 123\n123\n123
C 1\n2\n3
D 111\n222\n333
Correct Answer:  A. 1\n12\n123
EXPLANATION

Nested loop: outer loop runs 3 times, inner loop runs i times. Prints 1, then 12, then 123 on separate lines.

Test
Q.357 Medium Control Flow
Which of the following statements about switch case is TRUE?
A break is mandatory in every case
B default case must be the last case
C Multiple cases can execute if break is missing (fall-through)
D Switch can only work with integer values
Correct Answer:  C. Multiple cases can execute if break is missing (fall-through)
EXPLANATION

Without break, execution falls through to the next case. Default can be anywhere, and modern C allows switch with other types.

Test
Q.358 Medium Control Flow
What is the output?
int x = 10;
while(x-- > 5) {
printf("%d ", x);
}
A 9 8 7 6 5
B 10 9 8 7 6
C 9 8 7 6
D 10 9 8 7 6 5
Correct Answer:  C. 9 8 7 6
EXPLANATION

x-- returns the value before decrementing. Loop runs while value > 5: prints 9,8,7,6 (when x becomes 5, condition fails).

Test
Q.359 Medium Control Flow
What is the output of the following code?
int x = 5;
if(x > 3)
if(x < 10)
printf("Pass");
else
printf("Fail");
A Pass
B Fail
C No output
D Compilation error
Correct Answer:  A. Pass
EXPLANATION

The inner if condition (x < 10) is true, so 'Pass' is printed. The else is associated with the inner if, not the outer one.

Test
Q.360 Medium Control Flow
What does continue do in a for loop with multiple statements in body?
A Skips remaining body statements and goes to next iteration
B Exits the loop completely
C Skips only the next statement
D Causes compilation error
Correct Answer:  A. Skips remaining body statements and goes to next iteration
EXPLANATION

continue skips all remaining statements in the current loop iteration and jumps to the increment/condition check for the next iteration.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips