What is the output of: int add(int a, int b) { int result = a + b; return result; } If called as add(5, 3)?
Answer: A
The function simply adds two integers and returns their sum, which is 5 + 3 = 8.
Q.102Easy
What will be the output?
int func(int *p) { return *p; }
int main() { int x = 10; printf("%d", func(&x)); }
Answer: A
The function receives a pointer to x, dereferences it with *p, and returns the value 10.
Q.103Easy
In the context of recursion, which of the following is essential to avoid infinite recursion?
Answer: B
A base case is essential in recursive functions to provide a termination condition, otherwise the function will recurse infinitely.
Q.104Easy
Which storage class specifier allows a function to be called only within the file where it is defined?
Answer: A
The static keyword restricts function scope to the file in which it is declared, preventing external linkage.
Q.105Easy
What is the return type of a function that performs an action but doesn't return any value?
Answer: B
The void keyword is used as return type for functions that do not return any value.
Advertisement
Q.106Easy
In C, what happens when a function is called before its declaration?
Answer: B
C requires function declaration before use (forward declaration or definition). Calling without prior declaration causes compilation error in modern C standards.
Q.107Easy
Which of the following is an example of call by value in C?
Answer: B
Call by value passes a copy of the variable. Changes inside the function don't affect the original variable. Option B demonstrates this principle.
Q.108Easy
What is the main difference between function declaration and function definition?
Answer: A
Declaration (prototype) informs compiler about function signature; definition provides the actual implementation body.
Q.109Easy
What is the primary purpose of function prototypes in C?
Answer: A
Function prototypes inform the compiler about function name, return type, and parameters before the actual definition, enabling proper type checking during compilation.
Q.110Easy
Which of the following is a valid function declaration in C?
Answer: A
The correct syntax is return_type function_name(parameters). Option A follows proper C syntax with int as return type, func as name, and void indicating no parameters.
Q.111Easy
What happens when a function is called without a return statement reaching the end?
Answer: B
If a non-void function doesn't explicitly return a value, it returns whatever garbage value happens to be in the return register, leading to undefined behavior.
Q.112Easy
What will be the output of the following code?
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(5, add(3, 2))); return 0; }
Answer: A
Inner add(3,2) returns 5, then add(5,5) returns 10. Functions can be nested in arguments as long as return type matches parameter type.
Q.113Easy
What is the output of this recursive function?
int fact(int n) { if(n<=1) return 1; return n*fact(n-1); }
main() { printf("%d", fact(4)); }
Answer: A
fact(4) = 4*fact(3) = 4*3*fact(2) = 4*3*2*fact(1) = 4*3*2*1 = 24. This is a proper factorial implementation with correct base case.
Q.114Easy
In C, what is the purpose of the return statement in a void function?
Answer: C
In void functions, return statement (without value) can be used to exit the function prematurely. It's optional at the end since function exits automatically.
Q.115Easy
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.116Easy
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.117Easy
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.118Easy
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.119Easy
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.120Easy
What is the correct way to declare a 1D array of 10 integers in C?
Answer: A
In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.