Which approach is more efficient for passing large structures to functions?
Answer: B
Passing large structures by pointer is more efficient as only address (typically 4-8 bytes) is copied, not entire structure.
Q.342Easy
What is the primary purpose of function prototypes in C?
Answer: A
Function prototypes inform the compiler about function name, return type, and parameters before the actual definition, enabling proper type checking during compilation.
Q.343Easy
Which of the following is a valid function declaration in C?
Answer: A
The correct syntax is return_type function_name(parameters). Option A follows proper C syntax with int as return type, func as name, and void indicating no parameters.
Q.344Easy
What happens when a function is called without a return statement reaching the end?
Answer: B
If a non-void function doesn't explicitly return a value, it returns whatever garbage value happens to be in the return register, leading to undefined behavior.
Q.345Medium
In C, how many parameters can a function have at maximum?
Answer: C
The C standard does not impose a maximum limit on the number of function parameters, though practical implementations may have compiler-specific limits.
Advertisement
Q.346Medium
What is the scope of a static variable declared inside a function?
Answer: A
Static variables inside a function have local scope but static storage duration, meaning they retain their value between function calls and are initialized only once.
Q.347Medium
Which calling convention passes parameters through the stack from right to left?
Answer: A
The cdecl (C declaration) calling convention is the standard in C, pushing parameters onto the stack from right to left, with the caller responsible for stack cleanup.
Q.348Easy
What will be the output of the following code?
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(5, add(3, 2))); return 0; }
Answer: A
Inner add(3,2) returns 5, then add(5,5) returns 10. Functions can be nested in arguments as long as return type matches parameter type.
Q.349Medium
What is the difference between call by value and call by reference in C?
Answer: B
C supports call by value (default) and call by reference (using pointers). Call by value passes a copy; call by reference passes the address allowing modifications to original.
Q.350Medium
Analyze the following pointer to function declaration: int (*ptr)(int, int);
Answer: B
The parentheses around (*ptr) indicate ptr is a pointer. The remaining (int, int) shows it points to a function taking two int arguments and returning int.
Q.351Easy
What is the output of this recursive function?
int fact(int n) { if(n<=1) return 1; return n*fact(n-1); }
main() { printf("%d", fact(4)); }
Answer: A
fact(4) = 4*fact(3) = 4*3*fact(2) = 4*3*2*fact(1) = 4*3*2*1 = 24. This is a proper factorial implementation with correct base case.
Q.352Medium
Which of the following is true about function pointers in C?
Answer: B
Function pointers are powerful features enabling dynamic function selection at runtime, crucial for callbacks, function arrays, and design patterns like strategy pattern.
Q.353Medium
What is the primary advantage of using inline functions?
Answer: B
Inline functions request the compiler to replace function calls with actual function code, eliminating call overhead. However, compiler may ignore inline suggestion.
Q.354Medium
Consider the function: void func(int *arr, int size). Which statement is correct?
Answer: B
Array names decay to pointers in function calls. The parameter arr receives the address of the first element, so modifications affect the original array.
Q.355Hard
What does the restrict keyword do when used with pointer parameters in C99?
Answer: B
The restrict keyword (C99) is a promise to the compiler that the pointer is the only way to access that memory during its lifetime, allowing aggressive optimizations.
Q.356Medium
Which approach correctly implements a function returning multiple values?
Answer: D
Both approaches are valid in C: returning a struct with multiple fields or using pointers as output parameters. Using globals is possible but not recommended.
Q.357Hard
What will this code output?
int x = 10;
int* getAddress() { return &x; }
main() { int *ptr = getAddress(); printf("%d", *ptr); }
Answer: A
Since x is static (global scope), returning its address is safe and the pointer remains valid. The output is 10. If x were local, it would be undefined behavior.
Q.358Easy
In C, what is the purpose of the return statement in a void function?
Answer: C
In void functions, return statement (without value) can be used to exit the function prematurely. It's optional at the end since function exits automatically.
Q.359Hard
What happens when a function with variadic parameters is called with fewer arguments than expected?
Answer: C
Variadic functions (using ...) don't validate argument count. Calling with fewer arguments leads to undefined behavior as the function reads undefined values from stack.
Q.360Medium
Which of the following correctly declares a variadic function?
Answer: A
Variadic functions use ... syntax, and at least one named parameter must precede it. Option A is correct; Option B violates requirement of at least one named parameter.