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 371–380 of 490
Topics in C Programming
Q.371 Medium Control Flow
Predict the output:
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(i + j == 1) continue;
printf("Done");
A Done
B No output
C Done is printed 3 times
D Syntax error
Correct Answer:  A. Done
EXPLANATION

continue only affects the inner loop, not the outer. The loops complete normally and 'Done' is printed once after both loops finish.

Test
Q.372 Medium Control Flow
What happens with this nested if?
if(1) if(0) printf("A"); else printf("B");
A A
B B
C No output
D Syntax error
Correct Answer:  B. B
EXPLANATION

The else binds to the nearest if (inner if). Outer if(1) is true, inner if(0) is false, so else executes printing 'B'.

Test
Q.373 Medium Control Flow
In a switch statement with integer cases, can a case have a floating-point constant?
A Yes, always
B No, never
C Only if explicitly cast
D Only in newer C standards
Correct Answer:  B. No, never
EXPLANATION

Case labels must be constant integral expressions (int, char, etc.). Floating-point constants are not allowed as case labels.

Test
Q.374 Medium Control Flow
What is the final value of x?
int x = 0;
for(int i = 1; i
A 9
B 15
C 10
D 8
Correct Answer:  A. 9
EXPLANATION

continue skips even values. x accumulates: 1(i=1) + 3(i=3) + 5(i=5) = 9. Values i=2,4 are skipped.

Test
Q.375 Medium Control Flow
What will be printed?
for(int i = 0; i < 3; i++) {
if(i == 1) goto skip;
printf("%d ", i);
}
skip: printf("End");
A 0 1 2 End
B 0 2 End
C 0 End
D 1 2 End
Correct Answer:  B. 0 2 End
EXPLANATION

When i=1, goto skip jumps to the skip label, skipping the printf. i continues to 2 in the loop. Output: 0 2 End

Test
Q.376 Medium Control Flow
What is the output?
int x = 5;
switch(x) {
case 5: printf("Five");
case 6: printf("Six");
default: printf("Default");
}
A Five
B FiveSixDefault
C FiveSix
D Six
Correct Answer:  B. FiveSixDefault
EXPLANATION

Without a break statement after case 5, control falls through to case 6 and default. This is called fall-through behavior in switch statements.

Test
Q.377 Medium Control Flow
In a nested loop, if we use 'goto' statement, where does the control transfer?
A To the label specified in goto statement
B To the outer loop only
C To the beginning of the loop
D To the next iteration
Correct Answer:  A. To the label specified in goto statement
EXPLANATION

'goto' transfers control to the label specified, which can be anywhere in the program. It can jump out of nested structures to the labeled location.

Test
Q.378 Medium Control Flow
What is the output of the following code?
for(int i = 1; i
A 11 21 31 32
B 11 12 31 32
C 11 31 32
D 11 12 21 31 32
Correct Answer:  C. 11 31 32
EXPLANATION

The break statement only exits the inner loop. When i=2 and j=1, inner loop breaks. i=3 executes normally. Output: 11 31 32

Test
Q.379 Medium Control Flow
What will be the output of the following code?
int i = 0;
while(i < 3) {
printf("%d ", i++);
if(i == 2) continue;
}
A 0 1 2
B 0 1
C 0 2
D Infinite loop
Correct Answer:  A. 0 1 2
EXPLANATION

The loop prints 0, then i becomes 1. When i becomes 2, continue skips the rest but the loop continues. i becomes 3 and loop exits. Output: 0 1 2

Test
Q.380 Medium Control Flow
Which statement is best suited for implementing a menu-driven program with exact matching?
A if-else chain
B while loop
C switch statement
D for loop
Correct Answer:  C. switch statement
EXPLANATION

A switch statement is ideal for menu-driven programs where you match user input against specific cases. It's more efficient and readable than multiple if-else statements for this purpose.

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