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.362Easy
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.363Easy
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.
Q.364Easy
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.365Medium
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.
Advertisement
Q.366Medium
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.367Medium
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.368Medium
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.
Q.369Hard
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.370Easy
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.371Hard
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.372Medium
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.373Medium
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.374Medium
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.375Medium
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.376Hard
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.377Hard
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.378Hard
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.379Medium
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.380Medium
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.