Home Subjects C Programming Functions

C Programming
Functions

C language from basics to advanced placement prep

28 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 28
Topics in C Programming
Q.11 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.12 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.13 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.14 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.15 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.16 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.17 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.18 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
Q.19 Easy Functions
What is the output of: int add(int a, int b) { int result = a + b; return result; } If called as add(5, 3)?
A 8
B 5
C 3
D Undefined
Correct Answer:  A. 8
EXPLANATION

The function simply adds two integers and returns their sum, which is 5 + 3 = 8.

Test
Q.20 Easy Functions
Consider: int func(int x) { return ++x; } What is the difference if we use x++ instead of ++x?
A No difference in return value
B ++x returns x+1, x++ returns original x
C x++ is faster than ++x
D Depends on compiler optimization
Correct Answer:  B. ++x returns x+1, x++ returns original x
EXPLANATION

Pre-increment (++x) increments and returns the new value, while post-increment (x++) increments but returns the old value.

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