Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 341–350 of 499
Topics in C Programming
Q.341 Medium Functions
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
Correct Answer:  A. 5
EXPLANATION

Since parameters are passed by value, changes to 'x' inside modify() don't affect 'a' in main(). Output is 5.

Take Test
Q.342 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.

Take Test
Q.343 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.

Take Test
Q.344 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.

Take Test
Q.345 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.

Take Test
Q.346 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.

Take Test
Q.347 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.

Take Test
Q.348 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.

Take Test
Q.349 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.

Take Test
Q.350 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'.

Take Test
IGET
iget AI
Online · Ask anything about exams
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