Which keyword is used to pass arguments by reference in C?
Answer: B
C does not have a 'ref' keyword like C++. Pointers are used to achieve pass-by-reference semantics in C by passing the address of a variable.
Q.82Medium
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.83Medium
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.84Medium
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.
Q.85Medium
What is the primary purpose of function pointers in C?
Answer: B
Function pointers enable polymorphism by allowing runtime selection of which function to call. They are crucial for implementing callbacks and dynamic function dispatch.
Advertisement
Q.86Hard
How are function arguments evaluated in C?
Answer: C
The C standard does not specify the order of evaluation of function arguments. The order is implementation-dependent and can vary between compilers.
Q.87Easy
What is the difference between declaring a function and defining a function?
Answer: A
A declaration tells the compiler about the function's signature (return type, name, parameters); a definition provides the actual implementation (function body).
Q.88Hard
In the context of function pointers, what does the restrict keyword do?
Answer: B
The restrict keyword informs the compiler that the pointer is the sole means of accessing the data it points to, allowing for optimization. It's a hint for compiler optimization.
Q.89Medium
Which of the following is a valid way to return multiple values from a function in C?
Answer: D
C provides multiple methods to return values: structs for encapsulation, pointers for indirect modification, and global variables (though not recommended). All three are technically valid approaches.
Q.90Medium
What happens if a function is declared but never defined in C?
Answer: B
If a function is declared but not defined, the compiler generates code to call it (compilation succeeds), but the linker fails to find the function definition, resulting in a linker error.
Q.91Medium
Consider a function that modifies an array passed as a parameter. Which statement is true?
Answer: B
When an array is passed to a function, it decays to a pointer to its first element. This means modifications to array elements affect the original array outside the function.
Q.92Medium
What is the purpose of function inlining in modern C compilers?
Answer: B
Inlining substitutes a function call with the actual function body at compile time, eliminating function call overhead. This is a compiler optimization for performance-critical code.
Q.93Hard
Which of the following about variadic functions is true?
Answer: A
Variadic functions must have at least one fixed parameter before the ellipsis (...). This allows the function to know where variadic arguments begin. Type checking is NOT enforced for variadic arguments.
Q.94Hard
What is a callback function in C?
Answer: B
A callback is a function pointer passed to another function, which then invokes it at some point. Callbacks are essential for event-driven programming and implementing custom behavior.
Q.95Hard
In C, what is the relationship between array parameters and pointers in functions?
Answer: B
When an array is used as a function parameter, it undergoes array-to-pointer decay, converting to a pointer to the first element. This is why size information is lost.
Q.96Medium
Which of the following demonstrates proper use of the return statement in error handling?
Answer: D
All three approaches are valid for error handling in C. Functions typically return NULL for pointers, negative values for integers, or use predefined error codes to indicate failure states.
Q.97Medium
A function in C is declared as: int calculate(int *arr, int size). When this function modifies the array elements, what happens to the original array passed from the calling function?
Answer: A
In C, arrays decay to pointers when passed to functions, meaning the address is passed. Any modifications through the pointer affect the original array. This is effectively pass-by-reference behavior for arrays.
Q.98Easy
Consider the function declaration: void func(int x); and later in the code: int result = func(5);. What will be the compilation result?
Answer: A
A void function cannot return a value. Attempting to assign the return value of a void function to a variable will cause a compilation error in standard C compilers.
Q.99Hard
In a recursive function implementing factorial calculation, the base case is missing. What is the most likely consequence during execution?
Answer: B
Without a base case, recursion never terminates. Each function call pushes data onto the stack. Eventually, the stack memory is exhausted, causing a stack overflow error. This is a runtime error, not a compile-time error.