What will happen when this code executes?
void func() { func(); } int main() { func(); }
Answer: A
This is infinite recursion with no base case, causing stack overflow as the function keeps calling itself.
Q.162Medium
Which of the following is a valid function pointer initialization?
Answer: D
Both forms are valid. Functions decay to function pointers, so both &printf and printf assign the function address correctly.
Q.163Medium
Consider the code: int calculate(int a, int b = 5) { return a + b; }. What is the issue?
Answer: B
Default parameters are a C++ feature, not available in standard C. C requires explicit arguments for all parameters.
Q.164Medium
What will be the output of this recursive function? int fact(int n) { if(n <= 1) return 1; return n * fact(n-1); } fact(5)
Answer: C
This calculates factorial. fact(5) = 5*4*3*2*1 = 120. Base case n<=1 stops recursion.
Q.165Medium
Which statement about function parameters passed as arrays is correct?
Answer: B
Arrays in C decay to pointers to their first element, effectively making them pass-by-reference. Changes inside function affect original array.
Advertisement
Q.166Medium
What is the purpose of the 'extern' keyword when used with a function?
Answer: A
extern allows you to declare a function defined elsewhere, enabling its use across multiple translation units.
Q.167Medium
Consider: void modify(int *ptr) { *ptr = 20; } int main() { int x = 10; modify(&x); printf("%d", x); }. Output?
Answer: B
This is call by reference using pointers. The function receives address of x, dereferences and modifies it to 20.
Q.168Medium
What does variadic function mean in C?
Answer: A
Variadic functions accept variable number of arguments using ellipsis (...) and accessed with va_list, va_arg macros.
Q.169Medium
Which of the following correctly demonstrates inline function usage for optimization?
Answer: B
inline is a hint to compiler to expand function at call site. It's supported in C99+ and compiler decides whether to inline or not.
Q.170Medium
What is the output of this code? void swap(int a, int b) { int temp = a; a = b; b = temp; } int main() { int x = 5, y = 10; swap(x, y); printf("%d %d", x, y); }
Answer: B
This is call-by-value. The function swaps copies of x and y, not the originals. Original values remain unchanged.
Q.171Medium
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.172Medium
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.173Medium
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.174Medium
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.175Medium
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.176Medium
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.177Medium
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.178Medium
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.179Medium
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.180Medium
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.