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.
Q.22Medium
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.23Medium
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.24Medium
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.25Medium
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.
Advertisement
Q.26Medium
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.27Medium
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.28Medium
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.29Medium
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.30Medium
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.31Medium
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.32Medium
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.33Medium
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.34Medium
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.35Medium
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.36Medium
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.37Medium
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.38Medium
Which of the following correctly demonstrates function recursion termination?
Answer: B
A base case is essential in recursive functions to provide a stopping condition. Without it, the function will cause stack overflow. The base case ensures recursion terminates properly.
Q.39Medium
What does the const qualifier do when applied to function parameters?
Answer: A
When const is applied to a function parameter, it prevents modification of that parameter within the function body, making it immutable for the duration of the function.
Q.40Medium
Which statement about extern functions is correct?
Answer: B
extern functions have external linkage and can be accessed from other translation units. It's the default linkage for functions declared outside a file.