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 371–380 of 499
Topics in C Programming
Q.371 Medium Control Flow
Consider the code:
int x = 5;
if(x > 3)
if(x > 10)
printf("A");
else
printf("B");
Which statement best describes the output?
A Prints 'A' because x > 3
B Prints 'B' due to else binding to inner if
C Prints nothing
D Compilation error due to ambiguity
Correct Answer:  B. Prints 'B' due to else binding to inner if
EXPLANATION

The else binds to the nearest if statement (inner if). Since x=5 is not > 10, the inner condition fails and else executes, printing 'B'.

Take Test
Q.372 Medium Control Flow
What is the behavior of this code?
int i = 0;
while(1) {
i++;
if(i > 5) break;
}
A Infinite loop
B Loop runs 6 times (i = 1 to 6)
C Loop runs 5 times (i = 1 to 5)
D Syntax error
Correct Answer:  B. Loop runs 6 times (i = 1 to 6)
EXPLANATION

while(1) creates an infinite loop. i increments until i > 5 (i becomes 6), then break exits. Loop runs 6 iterations.

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

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

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

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

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

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

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

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

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