What is the output of the following code?
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 2; j++) {
if(i == 2 && j == 1) break;
printf("%d%d ", i, j);
}
}
Answer: C
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
Q.42Medium
In a nested loop, if we use 'goto' statement, where does the control transfer?
Answer: A
'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.
Q.43Medium
What is the output?
int x = 5;
switch(x) {
case 5: printf("Five");
case 6: printf("Six");
default: printf("Default");
}
Answer: B
Without a break statement after case 5, control falls through to case 6 and default. This is called fall-through behavior in switch statements.
Q.44Medium
What will be printed?
for(int i = 0; i < 3; i++) {
if(i == 1) goto skip;
printf("%d ", i);
}
skip: printf("End");
Answer: B
When i=1, goto skip jumps to the skip label, skipping the printf. i continues to 2 in the loop. Output: 0 2 End
Q.45Easy
Analyze the code: What happens when condition in if statement is false?
if(0) { statements; } else { statements; }
Answer: B
When the if condition is false (0 is false in C), the else block executes. This is basic if-else control flow.
Advertisement
Q.46Medium
What is the final value of x?
int x = 0;
for(int i = 1; i <= 5; i++) {
if(i % 2 == 0) continue;
x += i;
}
Answer: A
continue skips even values. x accumulates: 1(i=1) + 3(i=3) + 5(i=5) = 9. Values i=2,4 are skipped.
Q.47Easy
In the ternary operator (? :), what happens if the condition is false?
Answer: B
The ternary operator syntax is: condition ? true_expr : false_expr. If condition is false, false_expr is evaluated.
Q.48Easy
What will be the result?
for(int i = 1; i <= 4; i++) {
if(i == 3) break;
printf("%d ", i);
}
Answer: B
When i=3, break executes and exits the loop immediately. Only i=1 and i=2 are printed. Output: 1 2
Q.49Medium
In a switch statement with integer cases, can a case have a floating-point constant?
Answer: B
Case labels must be constant integral expressions (int, char, etc.). Floating-point constants are not allowed as case labels.
Q.50Easy
What is printed by this code?
int x = 1, y = 2;
if(x > y) printf("A");
else if(x < y) printf("B");
else printf("C");
Answer: B
Since x=1 and y=2, x>y is false, but x<y is true, so 'B' is printed. The else if condition matches.
Q.51Medium
What happens with this nested if?
if(1) if(0) printf("A"); else printf("B");
Answer: B
The else binds to the nearest if (inner if). Outer if(1) is true, inner if(0) is false, so else executes printing 'B'.
Q.52Medium
Predict the output:
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(i + j == 1) continue;
printf("Done");
Answer: A
continue only affects the inner loop, not the outer. The loops complete normally and 'Done' is printed once after both loops finish.
Q.53Medium
What is the behavior of this code?
int i = 0;
while(1) {
i++;
if(i > 5) break;
}
Answer: B
while(1) creates an infinite loop. i increments until i > 5 (i becomes 6), then break exits. Loop runs 6 iterations.
Q.54Easy
Which statement best describes the difference between break and continue?
Answer: A
break completely exits/terminates the loop. continue skips the rest of current iteration and jumps to the next iteration.
Q.55Easy
What value does the ternary operator return?
int result = (5 > 3) ? 10 : 20;
Answer: C
The condition (5 > 3) is true, so the ternary operator evaluates and returns the true expression value: 10.
Q.56Hard
What is the output of this complex nested loop?
for(int i = 1; i <= 2; i++) {
for(int j = 1; j <= 2; j++) {
if(i == j) continue;
printf("%d%d ", i, j);
}
}
Answer: B
continue skips when i==j. i=1: prints 12 (skips 11); i=2: prints 21 (skips 22). Output: 12 21
Q.57Easy
Which of the following control flow statements will cause a compilation error in C?
Answer: A
break and continue statements can only be used within loops or switch statements. Using break outside these constructs results in a compilation error.
Q.58Easy
What is the primary difference between while and do-while loops?
Answer: B
do-while loop checks the condition after executing the loop body, ensuring at least one execution. while loop checks before executing.
Q.59Easy
In a switch statement, if a case label is missing the break statement, what occurs?
Answer: C
Missing break causes fall-through behavior where execution continues to the next case label until a break or end of switch is encountered.
Q.60Easy
Which control flow statement allows jumping to a labeled location in C?
Answer: B
goto statement allows unconditional jump to a labeled location. Though generally discouraged, it's valid in C and sometimes used for error handling.