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.42Hard
What is the output of:
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(i == j) continue;
printf("Done");
Answer: A
continue skips current iteration but doesn't affect outer loop. After nested loops complete, 'Done' prints once.
Q.43Hard
What will this code do?
int i = 0;
while(i < 5) {
printf("%d ", i++);
if(i == 3) break;
}
Answer: A
Post-increment: prints 0 (i becomes 1), prints 1 (i becomes 2), prints 2 (i becomes 3). When i==3, break executes. Output: 0 1 2
Q.44Hard
Which statement best describes the 'dangling else' problem in C?
Answer: B
Dangling else refers to ambiguity when else could bind to multiple if statements. C resolves this by binding else to the nearest if.
Q.45Hard
What is the output?
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == j) continue;
printf("Done");
Answer: A
continue only skips the current iteration of innermost loop, not the outer. After both loops complete, 'Done' is printed once.
Advertisement
Q.46Hard
What will this code print?
int x = 0;
while(x < 3) {
printf("%d ", x++);
if(x == 2) continue;
printf("X ");
}
Answer: D
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.
Q.47Hard
What will be printed?
int i = 0, j = 0;
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
if(i + j == 2) break;
printf("%d%d ", i, j);
}
}
Answer: A
Inner break only exits the inner loop. i=0,j=0: prints 00; i=0,j=1: prints 01, breaks when j=2; i=1,j=0: prints 10, breaks when j=1; i=2,j=0: breaks immediately.
Q.48Hard
Consider the code:
int sum = 0;
for(int i = 1; i <= 10; i++) {
if(i % 2 == 0) continue;
sum += i;
}
printf("%d", sum);
What will be printed?
Answer: A
The loop adds only odd numbers (1,3,5,7,9) due to the continue statement when i is even. Sum = 1+3+5+7+9 = 25.
Q.49Hard
How can you modify a variable inside a function and reflect the change in the calling function?
Answer: D
All three methods work: return value, pass pointers, or use global variables. Each has different use cases and implications.
Q.50Hard
What is the output of this code?
int* getPointer(int *p) { return p; }
int main() { int a = 10; int *ptr = getPointer(&a); printf("%d", *ptr); }
Answer: A
The function receives the address of 'a', returns it, and dereferencing gives 10. However, returning pointers to local variables is risky in other contexts.
Q.51Hard
What are static local variables in functions used for?
Answer: A
Static local variables retain their value between function calls, initialized only once, and are stored in data segment.
Q.52Hard
What will be the output?
int counter() { static int count = 0; return ++count; }
int main() { printf("%d ", counter()); printf("%d ", counter()); printf("%d", counter()); }
Answer: B
Static variable 'count' retains its value. First call: 0+1=1, second: 1+1=2, third: 2+1=3.
Q.53Hard
Which of the following is TRUE about inline functions in C99 standard?
Answer: B
The 'inline' keyword is a hint to the compiler to replace function calls with the function body, reducing overhead but increasing code size.
Q.54Hard
What is function overloading in the context of C?
Answer: B
C does not support function overloading. To achieve similar functionality, use different names or variadic functions (using ...) or union of function pointers.
Q.55Hard
In C99 and later standards, what is the maximum number of parameters a function can have?
Answer: D
While C99 guarantees support for at least 127 parameters, the actual limit is implementation-dependent and varies by compiler.
Q.56Hard
What is the primary advantage of using function pointers in C?
Answer: B
Function pointers enable runtime polymorphism by allowing selection of which function to call based on runtime conditions.
Q.57Hard
How does the volatile keyword affect function behavior in C?
Answer: B
The volatile keyword tells the compiler not to optimize away variable accesses, ensuring the variable is read from memory each time.
Q.58Hard
What will happen if a recursive function has no base case?
Answer: B
Without base case, recursion never stops, causing stack to overflow as return addresses keep accumulating.
Q.59Hard
Consider mutual recursion: void funcA(int n); void funcB(int n); funcA calls funcB and vice versa. What is required?
Answer: A
For mutual recursion, you need forward declaration (prototype) of at least one function before it's called by another.
Q.60Hard
What is the correct way to return multiple values from a function in C?
Answer: D
C doesn't support multiple return values. Both pointers (call-by-reference) and structs are valid techniques.