C Programming — Functions
C language from basics to advanced placement prep
28 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 28 questions in Functions
Q.1 Easy Functions
Consider the function declaration: void func(int x); and later in the code: int result = func(5);. What will be the compilation result?
A Compilation error because func returns void but is assigned to an int variable
B Compilation warning but will compile successfully; result will be undefined
C Successful compilation and result will be 5
D Runtime error will occur
Correct Answer:  A. Compilation error because func returns void but is assigned to an int variable
EXPLANATION

A void function cannot return a value. Attempting to assign the return value of a void function to a variable will cause a compilation error in standard C compilers.

Take Test
Q.2 Easy Functions
What is the difference between declaring a function and defining a function?
A Declaration specifies the function signature; definition includes the function body
B They are the same thing in C
C Definition comes before declaration
D Declaration includes the function body; definition does not
Correct Answer:  A. Declaration specifies the function signature; definition includes the function body
EXPLANATION

A declaration tells the compiler about the function's signature (return type, name, parameters); a definition provides the actual implementation (function body).

Take Test
Q.3 Easy Functions
Which keyword is used to pass arguments by reference in C?
A ref
B Pointers are used to simulate pass-by-reference
C reference
D &reference
Correct Answer:  B. Pointers are used to simulate pass-by-reference
EXPLANATION

C does not have a 'ref' keyword like C++. Pointers are used to achieve pass-by-reference semantics in C by passing the address of a variable.

Take Test
Q.4 Easy Functions
What is the scope of a static function in C?
A Global scope across all files
B Limited to the file in which it is defined
C Limited to the function block only
D Available to all functions in the current block
Correct Answer:  B. Limited to the file in which it is defined
EXPLANATION

A static function has internal linkage and is limited to the file in which it is defined. It cannot be accessed from other translation units.

Take Test
Q.5 Easy Functions
Which of the following is a correct function prototype in C?
A int func();
B func int();
C int func(void) { }
D func (void) int;
Correct Answer:  A. int func();
EXPLANATION

A function prototype must have the return type first, followed by the function name and parameter list in parentheses. Option A is the correct syntax.

Take Test
Advertisement
Q.6 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.7 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.8 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.9 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.10 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
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