Which of the following correctly declares a function pointer that points to a function returning int and taking two int parameters?
The correct syntax for function pointer is return_type (*pointer_name)(parameter_types). Option A is correct.
In C, when a function is called with fewer arguments than declared, what happens?
Old-style K&R C declarations don't perform argument checking, allowing calls with fewer arguments. Modern prototyped functions generate compiler errors.
What is the scope of a function parameter in C?
Function parameters have function scope, meaning they are accessible throughout the entire function body.
Which keyword is used to create a function that can be expanded inline by the compiler without actual function call overhead?
The 'inline' keyword (introduced in C99) suggests to the compiler to replace function calls with actual code, reducing call overhead.
What will be printed by this code?
void func(int arr[10]) { printf("%lu", sizeof(arr)); }
int main() { int a[10]; func(a); }
When arrays are passed to functions, they decay to pointers. sizeof(arr) returns the size of the pointer, not the array.
Advertisement
What is the correct way to declare a function that accepts variable number of arguments?
Variadic functions require at least one named parameter before the ellipsis. Both options B and C follow the correct syntax.
Which of the following is true about a static function in C?
A static function has file scope and cannot be accessed from other translation units, providing encapsulation.
What happens if a function declared as returning int doesn't contain a return statement?
Without an explicit return statement, the function returns whatever value is in the return register, which is undefined behavior.
Consider: int func(int x) { return ++x; } What is the difference if we use x++ instead of ++x?
Pre-increment (++x) increments and returns the new value, while post-increment (x++) increments but returns the old value.
Which of the following correctly represents a callback function scenario?
A callback function is a function pointer passed to another function, which calls it at a later point in time.
What is the output of: int add(int a, int b) { int result = a + b; return result; } If called as add(5, 3)?
The function simply adds two integers and returns their sum, which is 5 + 3 = 8.
In C99 and later standards, what is the maximum number of parameters a function can have?
While C99 guarantees support for at least 127 parameters, the actual limit is implementation-dependent and varies by compiler.
What will be the output?
int func(int *p) { return *p; }
int main() { int x = 10; printf("%d", func(&x)); }
The function receives a pointer to x, dereferences it with *p, and returns the value 10.
Which of the following about function declaration and definition is TRUE?
Functions can have multiple forward declarations but only one definition. This allows function prototypes in header files.
What is the primary advantage of using function pointers in C?
Function pointers enable runtime polymorphism by allowing selection of which function to call based on runtime conditions.
In the context of recursion, which of the following is essential to avoid infinite recursion?
A base case is essential in recursive functions to provide a termination condition, otherwise the function will recurse infinitely.
What will happen when this code executes?
void func() { func(); } int main() { func(); }
This is infinite recursion with no base case, causing stack overflow as the function keeps calling itself.
How does the volatile keyword affect function behavior in C?
The volatile keyword tells the compiler not to optimize away variable accesses, ensuring the variable is read from memory each time.
Which of the following is a valid function pointer initialization?
Both forms are valid. Functions decay to function pointers, so both &printf and printf assign the function address correctly.
Which storage class specifier allows a function to be called only within the file where it is defined?
The static keyword restricts function scope to the file in which it is declared, preventing external linkage.