What is the default return type of a function in C if not specified?
A void B int C float D char
In older C standards (before C99), if no return type is specified, the default is 'int'. However, this is deprecated in modern C standards.
What is the difference between function declaration and function definition?
A Declaration provides the function prototype; definition provides the actual implementation B They are the same thing C Declaration is mandatory; definition is optional D Definition comes before declaration always
Declaration (prototype) tells the compiler about the function signature; definition provides the actual function body and implementation.
What happens if a function does not have a return statement?
A Compilation error occurs B Runtime error occurs C An undefined/garbage value is returned D 0 is returned by default
If a function with a non-void return type lacks a return statement, it returns undefined/garbage value. For void functions, no return is needed.
Which of the following function calls is valid? int calculate(int a, float b, char c);
A calculate(5, 3.14, 'A'); B calculate(5); C calculate(5, 3.14); D calculate('A', 3.14, 5);
All three parameters must be provided in correct order and compatible types.
What is a recursive function?
A A function that calls itself directly or indirectly B A function that calls another function C A function that returns multiple values D A function that has no parameters
A recursive function is one that calls itself. It must have a base case to avoid infinite recursion.
What is the issue with the following code? int factorial(int n) { return n * factorial(n-1); }
A Syntax error B No base case, leading to infinite recursion and stack overflow C The function cannot call itself D Missing return type
The recursive function lacks a base case (like if n==0 return 1) to terminate recursion, causing infinite recursion and stack overflow.
In C, are function parameters passed by value or by reference by default?
A By value B By reference C Depends on the data type D Both simultaneously
C passes parameters by value by default. To achieve pass-by-reference effect, pointers must be used explicitly.
What will be the output? void modify(int x) { x = x + 10; } int main() { int a = 5; modify(a); printf("%d", a); }
A 5 B 15 C 10 D Error
Since parameters are passed by value, changes to 'x' inside modify() don't affect 'a' in main(). Output is 5.
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 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.
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.
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 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.
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.
Consider the code: int calculate(int a, int b = 5) { return a + b; }. What is the issue?
A Default parameters are allowed in C B Default parameters are NOT allowed in C (only in C++) C Syntax is incorrect D Return type is missing
Default parameters are a C++ feature, not available in standard C. C requires explicit arguments for all parameters.
What will be the output of this recursive function? int fact(int n) { if(n <= 1) return 1; return n * fact(n-1); } fact(5)
A 5 B 25 C 120 D Infinite recursion error
This calculates factorial. fact(5) = 5*4*3*2*1 = 120. Base case n<=1 stops recursion.