Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 181–190 of 303
Topics in C Programming
Q.181 Easy Functions
In C, what is the purpose of the return statement in a void function?
A It is optional and not needed
B To return 0 by default
C To exit the function immediately without returning a value
D To cause compilation error if used
Correct Answer:  C. To exit the function immediately without returning a value
EXPLANATION

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.

Take Test
Q.182 Easy Functions
What is the output of this recursive function?
int fact(int n) { if(n
A 24
B 10
C 12
D Stack overflow
Correct Answer:  A. 24
EXPLANATION

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.

Take Test
Q.183 Easy Functions
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; }
A 10
B 8
C Compilation error
D 5
Correct Answer:  A. 10
EXPLANATION

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.

Take Test
Q.184 Easy Functions
What happens when a function is called without a return statement reaching the end?
A Compilation error occurs
B An undefined/garbage value is returned
C 0 is automatically returned
D NULL is returned
Correct Answer:  B. An undefined/garbage value is returned
EXPLANATION

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.

Take Test
Q.185 Easy Functions
Which of the following is a valid function declaration in C?
A int func(void);
B func int();
C void int func();
D int func() void;
Correct Answer:  A. int func(void);
EXPLANATION

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.

Take Test
Q.186 Easy Functions
What is the primary purpose of function prototypes in C?
A To declare the function signature before its definition
B To allocate memory for function variables
C To optimize function execution speed
D To prevent function from being called
Correct Answer:  A. To declare the function signature before its definition
EXPLANATION

Function prototypes inform the compiler about function name, return type, and parameters before the actual definition, enabling proper type checking during compilation.

Take Test
Q.187 Easy Functions
What is the main difference between function declaration and function definition?
A Declaration specifies name and parameters; definition provides implementation
B Declaration includes return type; definition doesn't
C They are exactly the same
D Definition must come before declaration
Correct Answer:  A. Declaration specifies name and parameters; definition provides implementation
EXPLANATION

Declaration (prototype) informs compiler about function signature; definition provides the actual implementation body.

Take Test
Q.188 Easy Functions
Which of the following is an example of call by value in C?
A void func(int *p) { *p = 10; }
B void func(int p) { p = 10; }
C void func(int &p) { p = 10; }
D void func(int arr[]) { arr[0] = 10; }
Correct Answer:  B. void func(int p) { p = 10; }
EXPLANATION

Call by value passes a copy of the variable. Changes inside the function don't affect the original variable. Option B demonstrates this principle.

Take Test
Q.189 Easy Functions
In C, what happens when a function is called before its declaration?
A It executes successfully with default int return type
B Compilation error occurs
C Runtime error occurs
D Function is automatically declared as extern
Correct Answer:  B. Compilation error occurs
EXPLANATION

C requires function declaration before use (forward declaration or definition). Calling without prior declaration causes compilation error in modern C standards.

Take Test
Q.190 Easy Functions
What is the return type of a function that performs an action but doesn't return any value?
A int
B void
C null
D empty
Correct Answer:  B. void
EXPLANATION

The void keyword is used as return type for functions that do not return any value.

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