Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 711–720 of 1,000
Topics in C Programming
Q.711 Hard Control Flow
What will this code print?
int x = 0;
while(x < 3) {
printf("%d ", x++);
if(x == 2) continue;
printf("X ");
}
A 0 X 1 2 X
B 0 X 1 X 2 X
C 0 1 2
D 0 X 1 2
Correct Answer:  D. 0 X 1 2
EXPLANATION

Iteration 1: prints 0, x becomes 1, continue not triggered, prints X. Iteration 2: prints 1, x becomes 2, continue triggered, skips X. Iteration 3: prints 2, x becomes 3, condition fails.

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

Take Test
Q.713 Hard Control Flow
What is the output?
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == j) continue;
printf("Done");
A Done
B Done printed 9 times
C No output
D Compilation error
Correct Answer:  A. Done
EXPLANATION

continue only skips the current iteration of innermost loop, not the outer. After both loops complete, 'Done' is printed once.

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

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

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

Take Test
Q.717 Easy Control Flow
What is the purpose of the ternary operator (? :) in C?
A To replace multiple for loops
B To provide a shorthand for if-else statements
C To handle exceptions
D To declare three variables at once
Correct Answer:  B. To provide a shorthand for if-else statements
EXPLANATION

The ternary operator (condition ? true_value : false_value) is a concise alternative to if-else for simple conditional assignments.

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

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

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

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