Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 361–370 of 499
Topics in C Programming
Q.361 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.

Take Test
Q.362 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.

Take Test
Q.363 Medium Control Flow
Consider:
switch(x) {
case 1:
case 2:
case 3: printf("A"); break;
default: printf("B");
}
What advantage does stacking cases provide?
A Saves memory
B Allows same code for multiple case values without repetition
C Improves execution speed
D Makes code unreadable intentionally
Correct Answer:  B. Allows same code for multiple case values without repetition
EXPLANATION

Stacking cases (without break between them) allows multiple values to execute the same code block, reducing redundancy.

Take Test
Q.364 Medium Control Flow
What does the following code segment do?
int i = 0;
do {
printf("%d ", i);
} while(++i < 3);
A Prints: 0 1 2
B Prints: 1 2 3
C Prints nothing
D Infinite loop
Correct Answer:  A. Prints: 0 1 2
EXPLANATION

do-while executes body first (prints 0), then checks ++i < 3. Loop continues for i=1,2. When i=3, condition fails. Output: 0 1 2

Take Test
Q.365 Medium Control Flow
What is the key distinction between if-else and switch statements in terms of evaluation?
A if-else is faster than switch
B if-else evaluates conditions, switch uses jump table for integral constants
C switch can handle float types but if-else cannot
D if-else allows multiple conditions, switch allows only one
Correct Answer:  B. if-else evaluates conditions, switch uses jump table for integral constants
EXPLANATION

switch typically uses jump tables for efficient multi-way branching with integral values, while if-else evaluates boolean expressions sequentially.

Take Test
Q.366 Medium Control Flow
Consider the code:
int x = 0;
while(1) {
if(++x > 3) break;
printf("%d ", x);
}
What is the output?
A 0 1 2
B 1 2 3
C 1 2
D Infinite loop with no output
Correct Answer:  B. 1 2 3
EXPLANATION

Pre-increment ++x happens first. When x becomes 4, condition is true and loop breaks. Values printed: x=1,2,3 (before x reaches 4).

Take Test
Q.367 Medium Control Flow
What happens when you use break in a nested loop structure?
A Breaks both inner and outer loop
B Breaks only the immediate (inner) loop
C Breaks all loops in the program
D Causes compilation error
Correct Answer:  B. Breaks only the immediate (inner) loop
EXPLANATION

break statement exits only the innermost loop it's in. To break outer loop, you need additional logic or goto statement.

Take Test
Q.368 Medium Control Flow
Analyze: What is printed by this code?
for(int i = 1; i
A 1 22 333
B 1 2 3
C 123 123 123
D 1 22 333 (with spaces)
Correct Answer:  D. 1 22 333 (with spaces)
EXPLANATION

Outer loop: i=1,2,3. Inner loop repeats i times. When i=1: print '1' once. i=2: print '2' twice. i=3: print '3' thrice. Each iteration separated by space.

Take Test
Q.369 Medium Control Flow
Which of the following is a valid use of the switch statement in C?
A switch(1.5) { case 1.5: break; }
B switch("hello") { case "hello": break; }
C switch(x) { case 1: case 2: case 3: printf("A"); }
D switch(x > 5) { case true: break; }
Correct Answer:  C. switch(x) { case 1: case 2: case 3: printf("A"); }
EXPLANATION

Switch works with integral types only. Multiple case labels before statements (fall-through) is valid. Strings and floats are not allowed.

Take Test
Q.370 Medium Control Flow
What does the following code segment accomplish?
int i = 0;
while(i < 5) {
if(i == 2) {
i++;
continue;
}
printf("%d ", i);
i++;
}
A Prints: 0 1 2 3 4
B Prints: 0 1 3 4
C Prints: 0 1
D Infinite loop
Correct Answer:  B. Prints: 0 1 3 4
EXPLANATION

When i==2, continue skips printf but still increments i. So 2 is not printed. Output: 0 1 3 4

Take Test
IGET
iget AI
Online · Ask anything about exams
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