Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 181–190 of 291
Topics in C Programming
Q.181 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.

Test
Q.182 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.

Test
Q.183 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.

Test
Q.184 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.

Test
Q.185 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.

Test
Q.186 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.

Test
Q.187 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.

Test
Q.188 Easy Functions
Which storage class specifier allows a function to be called only within the file where it is defined?
A static
B extern
C auto
D register
Correct Answer:  A. static
EXPLANATION

The static keyword restricts function scope to the file in which it is declared, preventing external linkage.

Test
Q.189 Easy Functions
In the context of recursion, which of the following is essential to avoid infinite recursion?
A Using static variables
B A base case that terminates recursion
C Declaring the function as inline
D Using pointers in function parameters
Correct Answer:  B. A base case that terminates recursion
EXPLANATION

A base case is essential in recursive functions to provide a termination condition, otherwise the function will recurse infinitely.

Test
Q.190 Easy Functions
What will be the output?
int func(int *p) { return *p; }
int main() { int x = 10; printf("%d", func(&x)); }
A 10
B Address of x
C Garbage value
D Compiler error
Correct Answer:  A. 10
EXPLANATION

The function receives a pointer to x, dereferences it with *p, and returns the value 10.

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