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.62Medium
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.
Q.63Medium
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.64Medium
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.65Easy
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.
Advertisement
Q.66Medium
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.67Medium
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.68Easy
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.69Medium
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.70Medium
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.71Medium
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.72Hard
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.73Medium
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.74Hard
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.75Easy
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.76Hard
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.77Medium
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.
Q.78Medium
What will be the output of this code?
int counter = 0;
void increment() { static int count = 0; count++; counter++; }
main() { increment(); increment(); printf("%d %d", count, counter); }
Answer: C
The static variable 'count' is local to increment() and inaccessible from main(). Trying to print 'count' causes compilation error: undefined identifier.
Q.79Easy
Which of the following is a correct function prototype in C?
Answer: A
A function prototype must have the return type first, followed by the function name and parameter list in parentheses. Option A is the correct syntax.
Q.80Easy
What is the scope of a static function in C?
Answer: B
A static function has internal linkage and is limited to the file in which it is defined. It cannot be accessed from other translation units.