C questions in placement tests and university exams are rarely about syntax alone. Most of what you will find here is output prediction, pointer arithmetic, arrays and strings, structures and unions, storage classes, recursion, and file handling. The explanations walk through memory behaviour step by step, which is usually where the confusion sits rather than in the code itself.
What will be the output of the following C code? int x = 5; if (x > 3) printf("A"); else printf("B");
Answer: A
Since x = 5 and 5 > 3 is true, the if block executes and prints 'A'.
Q.2Easy
Which of the following is NOT a valid control flow statement in C?
Answer: B
foreach is not a standard C control flow statement. C has if-else, switch, for, while, do-while, and goto.
Q.3Easy
What is the output of this code? for (int i = 0; i < 3; i++) printf("%d ", i);
Answer: A
The loop runs from i=0 to i=2 (i < 3), printing '0 1 2 '.
Q.4Easy
What is the difference between 'break' and 'continue' in loops?
Answer: A
break terminates the loop entirely, while continue jumps to the next iteration without executing remaining statements.
Q.5Medium
What will be printed? int x = 0; if (x = 5) printf("True"); else printf("False");
Answer: A
x = 5 assigns 5 to x and evaluates to 5 (non-zero), which is true. So 'True' is printed.
Q.6Medium
What is the output? for (int i = 1; i <= 5; i++) { if (i == 3) break; printf("%d ", i); }
Answer: A
When i becomes 3, break is executed, exiting the loop. So only 1 and 2 are printed.
Q.7Medium
What does the following nested if-else produce? int a = 10, b = 20; if (a > b) if (b > 0) printf("X"); else printf("Y");
Answer: B
The else clause pairs with the inner if. Since a > b is false, the else block executes printing 'Y'.
Q.8Medium
What is the output of this switch statement? int x = 2; switch(x) { case 1: printf("One"); break; case 2: printf("Two"); case 3: printf("Three"); break; default: printf("Other"); }
Answer: B
Case 2 matches. Since there's no break after case 2, fall-through occurs to case 3, printing 'TwoThree'.
Q.9Medium
How many times will this loop execute? for (int i = 0; i < 5; ++i) { if (i == 2) continue; if (i == 4) break; }
Answer: C
Loop runs for i=0,1,2,3. When i=4, break is executed. The body executes 4 times (iterations for i=0,1,2,3).
Q.10Medium
What is printed by this code? int x = 5; while (x-- > 0) printf("%d ", x);
Answer: B
x-- returns 5 first, then decrements to 4. Loop runs while x > 0, printing 4, 3, 2, 1, 0.
Q.11Medium
What is the output? int n = 1; do { printf("%d ", n); n++; } while (n > 5);
Answer: A
The do-while executes once (prints 1), then n becomes 2. Since 2 > 5 is false, the loop exits.
Q.12Easy
Analyze the ternary operator: int x = (5 > 3) ? 10 : 20; What is the value of x?
Answer: A
Since 5 > 3 is true, the ternary operator returns 10, so x = 10.
Q.13Hard
What is the output of this program? for (int i = 1; i <= 3; i++) for (int j = 1; j <= 2; j++) printf("%d", i*j); printf("\n");
Answer: A
Nested loops: outer i=1,2,3; inner j=1,2. Prints products: 1*1=1, 1*2=2 (newline), 2*1=2, 2*2=4 (newline), etc.
Q.14Easy
What is the behavior of goto in C?
Answer: A
goto transfers program control to a labeled location, though it's discouraged for code readability.
Q.15Medium
Determine the output: int i = 0; while (i < 3) { printf("%d ", i++); }
Answer: A
i starts at 0. Loop prints i then increments: prints 0, then 1, then 2. When i becomes 3, condition fails.
Q.16Medium
What does this code segment output? for (int i = 0; i < 5; i++) { if (i % 2 == 0) continue; printf("%d ", i); }
Answer: A
continue skips even numbers. Loop prints only odd values: 1 and 3.
Q.17Easy
Which statement is used to skip remaining iterations and move to next iteration?
Answer: B
continue is the C keyword that jumps to the next iteration of the loop.
Q.18Hard
What is the output of this complex nested control flow? int x = 1, y = 2; if (x < y) { x++; y--; if (x == y) printf("Equal"); else printf("NotEqual"); }
Answer: A
x=1, y=2. Since 1 < 2, x becomes 2 and y becomes 1. Now x != y, but after operations x=2, y=1. Wait: x++ makes x=2, y-- makes y=1. So x==y is false, printing 'NotEqual'. Rechecking: 1 < 2 is true, so enter if. x becomes 2, y becomes 1. 2 == 1 is false, so else executes, printing 'NotEqual'.
Q.19Easy
In C, which control flow statement is used to terminate a loop prematurely?
Answer: A
The 'break' statement is used to exit or terminate a loop immediately. 'continue' skips the current iteration, 'exit' terminates the entire program.
Q.20Medium
Which of the following is NOT a valid use of the goto statement in C?
Answer: C
goto cannot jump across function boundaries. It can only jump within the same function to a labeled statement either forward or backward.