Showing 91–100 of 100 questions
in Functions
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
Correct Answer:
A. A function that calls itself directly or indirectly
EXPLANATION
A recursive function is one that calls itself. It must have a base case to avoid infinite recursion.
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);
Correct Answer:
A. calculate(5, 3.14, 'A');
EXPLANATION
All three parameters must be provided in correct order and compatible types.
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
Correct Answer:
C. An undefined/garbage value is returned
EXPLANATION
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.
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
Correct Answer:
A. Declaration provides the function prototype; definition provides the actual implementation
EXPLANATION
Declaration (prototype) tells the compiler about the function signature; definition provides the actual function body and implementation.
How many times can a function be called in a C program?
A
Only once
B
Maximum 10 times
C
Unlimited times
D
Maximum 100 times
Correct Answer:
C. Unlimited times
EXPLANATION
A function can be called as many times as needed within a program, limited only by memory and stack constraints.
What will be the output of the following code?
int func(int x) { return x * 2; }
int main() { printf("%d", func(5)); }
EXPLANATION
func(5) returns 5 * 2 = 10, which is then printed.
Which of the following is a correct function declaration?
A
int add(int a, int b);
B
add int(a, b);
C
int add a, b;
D
add(int a, int b) int;
Correct Answer:
A. int add(int a, int b);
EXPLANATION
Function declaration syntax is: return_type function_name(parameter_list);
What is the default return type of a function in C if not specified?
A
void
B
int
C
float
D
char
EXPLANATION
In older C standards (before C99), if no return type is specified, the default is 'int'. However, this is deprecated in modern C standards.
Which keyword is used to define a function in C?
A
function
B
def
C
No keyword needed, just return type and name
D
func
Correct Answer:
C. No keyword needed, just return type and name
EXPLANATION
In C, functions are defined by specifying the return type followed by the function name and parameters. No specific 'function' keyword is used.
What is the primary purpose of using functions in C programming?
A
To modularize code and improve reusability
B
To increase memory consumption
C
To slow down program execution
D
To eliminate the need for loops
Correct Answer:
A. To modularize code and improve reusability
EXPLANATION
Functions allow code reusability, modularity, and easier maintenance. They break down complex problems into smaller, manageable pieces.