Home Subjects C Programming Functions

C Programming
Functions

C language from basics to advanced placement prep

47 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–47 of 47
Topics in C Programming
Q.41 Medium Functions
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
Correct Answer:  A. By value
EXPLANATION

C passes parameters by value by default. To achieve pass-by-reference effect, pointers must be used explicitly.

Test
Q.42 Medium Functions
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
Correct Answer:  B. No base case, leading to infinite recursion and stack overflow
EXPLANATION

The recursive function lacks a base case (like if n==0 return 1) to terminate recursion, causing infinite recursion and stack overflow.

Test
Q.43 Medium 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.

Test
Q.44 Medium Functions
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.

Test
Q.45 Medium Functions
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.

Test
Q.46 Medium Functions
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.

Test
Q.47 Medium Functions
What is the default return type of a function in C if not specified?
A void
B int
C float
D char
Correct Answer:  B. int
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.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips