Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 341–350 of 490
Topics in C Programming
Q.341 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.342 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.343 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.344 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.345 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.346 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
Q.347 Medium Control Flow
Which of the following statements about the switch-case construct is INCORRECT?
A The default case is mandatory in every switch statement
B Each case must end with a break statement to prevent fall-through
C Multiple cases can have the same code block if break is omitted
D The switch expression is evaluated only once
Correct Answer:  A. The default case is mandatory in every switch statement
EXPLANATION

The default case is optional in a switch statement. It executes when no case matches, but it is not mandatory. All other statements are correct properties of switch-case.

Test
Q.348 Medium Control Flow
Analyze this code:
for(int i = 0; i < 5; i++) {
if(i == 2) continue;
if(i == 3) break;
printf("%d ", i);
}
What is the output?
A 0 1
B 0 1 2 3
C 0 1 3
D 0 1 2
Correct Answer:  A. 0 1
EXPLANATION

When i=0: prints 0. When i=1: prints 1. When i=2: continue skips printf. When i=3: break terminates the loop. Output is '0 1'.

Test
Q.349 Medium Control Flow
In nested loops, if an inner loop contains a break statement, what happens?
A Only the inner loop terminates; the outer loop continues
B Both inner and outer loops terminate
C The entire program terminates
D The break statement is ignored in nested loops
Correct Answer:  A. Only the inner loop terminates; the outer loop continues
EXPLANATION

The break statement only exits the innermost loop that contains it. It does not affect the outer loop's execution. The outer loop will continue its iterations normally.

Test
Q.350 Medium Control Flow
In a for loop with multiple break statements in different conditions, which break will be executed?
A Only the first break encountered
B All break statements execute
C The break statement whose condition is true
D None of them execute unless the loop condition fails
Correct Answer:  C. The break statement whose condition is true
EXPLANATION

Only the break statement whose associated if condition evaluates to true will be executed, exiting the loop immediately.

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