Which of the following correctly declares a function pointer that points to a function returning int and taking two int parameters?
A int (*funcPtr)(int, int); B int *funcPtr(int, int); C funcPtr *int(int, int); D int funcPtr*(int, int);
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?
A Compiler error occurs B Runtime error occurs C Garbage values are passed for missing arguments D It compiles and runs without error if using old-style declarations
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?
A Global scope B File scope C Function scope D Block scope
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?
A extern B static C inline D register
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); }
A 40 B 10 C 8 (or 4 on 32-bit) D Compiler error
When arrays are passed to functions, they decay to pointers. sizeof(arr) returns the size of the pointer, not the array.
What is the correct way to declare a function that accepts variable number of arguments?
A void func(...); B void func(int, ...); C void func(int n, ...); D Both B and C are correct
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 It cannot be called from other files B It has only one instance throughout the program C It is stored in static memory segment D All of the above
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?
A Compiler error B Returns 0 by default C Returns undefined/garbage value D Depends on the compiler implementation
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?
A No difference in return value B ++x returns x+1, x++ returns original x C x++ is faster than ++x D Depends on compiler optimization
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 A function that calls itself recursively B A function pointer passed as argument to another function C A function that modifies global variables D A function declared with extern keyword
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)?
A 8 B 5 C 3 D Undefined
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?
A 255 B 256 C 127 D No fixed limit in standard, but implementation-dependent
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)); }
A 10 B Address of x C Garbage value D Compiler error
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?
A Declaration and definition must be in the same file B A function can be declared multiple times but defined only once C Definition is optional if declaration is provided D Declaration is optional in C
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?
A Faster execution than direct function calls B Dynamic function selection at runtime C Automatic memory management D Better code readability
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 Using static variables B A base case that terminates recursion C Declaring the function as inline D Using pointers in function parameters
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(); }
A Infinite recursion until stack overflow B Compiler error C Runtime error immediately D Program exits gracefully
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?
A It makes functions execute faster B It prevents compiler optimization of variable accesses C It changes function calling convention D It has no effect on functions
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?
A int (*fp)() = &printf; B int (*fp)() = printf; C int *fp = printf; D Both A and B
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?
A static B extern C auto D register
The static keyword restricts function scope to the file in which it is declared, preventing external linkage.