In a for loop with multiple break statements in different conditions, which break will be executed?
Answer: C
Only the break statement whose associated if condition evaluates to true will be executed, exiting the loop immediately.
Q.142Medium
In nested loops, if an inner loop contains a break statement, what happens?
Answer: A
The break statement only exits the innermost loop that contains it. It does not affect the outer loop's execution. The outer loop will continue its iterations normally.
Q.143Medium
Analyze this code:
for(int i = 0; i < 5; i++) {
if(i == 2) continue;
if(i == 3) break;
printf("%d ", i);
}
What is the output?
Answer: A
When i=0: prints 0. When i=1: prints 1. When i=2: continue skips printf. When i=3: break terminates the loop. Output is '0 1'.
Q.144Medium
Which of the following statements about the switch-case construct is INCORRECT?
Answer: A
The default case is optional in a switch statement. It executes when no case matches, but it is not mandatory. All other statements are correct properties of switch-case.
Q.145Medium
What is the default return type of a function in C if not specified?
Answer: B
In older C standards (before C99), if no return type is specified, the default is 'int'. However, this is deprecated in modern C standards.
Advertisement
Q.146Medium
What is the difference between function declaration and function definition?
Answer: A
Declaration (prototype) tells the compiler about the function signature; definition provides the actual function body and implementation.
Q.147Medium
What happens if a function does not have a return statement?
Answer: C
If a function with a non-void return type lacks a return statement, it returns undefined/garbage value. For void functions, no return is needed.
Q.148Medium
Which of the following function calls is valid?
int calculate(int a, float b, char c);
Answer: A
All three parameters must be provided in correct order and compatible types.
Q.149Medium
What is a recursive function?
Answer: A
A recursive function is one that calls itself. It must have a base case to avoid infinite recursion.
Q.150Medium
What is the issue with the following code?
int factorial(int n) { return n * factorial(n-1); }
Answer: B
The recursive function lacks a base case (like if n==0 return 1) to terminate recursion, causing infinite recursion and stack overflow.
Q.151Medium
In C, are function parameters passed by value or by reference by default?
Answer: A
C passes parameters by value by default. To achieve pass-by-reference effect, pointers must be used explicitly.
Q.152Medium
What will be the output?
void modify(int x) { x = x + 10; }
int main() { int a = 5; modify(a); printf("%d", a); }
Answer: A
Since parameters are passed by value, changes to 'x' inside modify() don't affect 'a' in main(). Output is 5.
Q.153Medium
Which of the following correctly declares a function pointer that points to a function returning int and taking two int parameters?
Answer: A
The correct syntax for function pointer is return_type (*pointer_name)(parameter_types). Option A is correct.
Q.154Medium
In C, when a function is called with fewer arguments than declared, what happens?
Answer: D
Old-style K&R C declarations don't perform argument checking, allowing calls with fewer arguments. Modern prototyped functions generate compiler errors.
Q.155Medium
What will be printed by this code?
void func(int arr[10]) { printf("%lu", sizeof(arr)); }
int main() { int a[10]; func(a); }
Answer: C
When arrays are passed to functions, they decay to pointers. sizeof(arr) returns the size of the pointer, not the array.
Q.156Medium
What is the correct way to declare a function that accepts variable number of arguments?
Answer: D
Variadic functions require at least one named parameter before the ellipsis. Both options B and C follow the correct syntax.
Q.157Medium
Which of the following is true about a static function in C?
Answer: A
A static function has file scope and cannot be accessed from other translation units, providing encapsulation.
Q.158Medium
What happens if a function declared as returning int doesn't contain a return statement?
Answer: C
Without an explicit return statement, the function returns whatever value is in the return register, which is undefined behavior.
Q.159Medium
Which of the following correctly represents a callback function scenario?
Answer: B
A callback function is a function pointer passed to another function, which calls it at a later point in time.
Q.160Medium
Which of the following about function declaration and definition is TRUE?
Answer: B
Functions can have multiple forward declarations but only one definition. This allows function prototypes in header files.