C Functions MCQ

Functions play a crucial role in structured programming. In C, they provide modularity, allowing a programmer to break down large programs into small, manageable functions or procedures. If you’re new to C programming or looking to brush up on your knowledge, here’s a quick quiz on functions!

Each question is followed by the correct answer and an explanation to help reinforce your knowledge.

1. What is the main purpose of a function in C?

A) Reduce repetition of code
B) Make the code more readable
C) Facilitate modular programming
D) All of the above

Answer:

D) All of the above

Explanation:

Functions provide modularity, reduce code repetition, and make the code more readable and maintainable.

2. Which of the following is the correct way to declare a function in C?

a) function functionName() { … }
b) declare functionName() { … }
c) int functionName() { … }
d) functionName: function() { … }

Answer:

c) int functionName() { … }

Explanation:

In C, functions are declared with their return type followed by the function name and parentheses.

3. What is the output of the following code?

void greet() {
    printf("Hello");
}
int main() {
    greet();
    return 0;
}
a) Error
b) 0
c) Hello
d) greet

Answer:

c) Hello

Explanation:

The function greet() is called within main() and prints “Hello” to the console.

4. How many values can a function return in C?

A) Multiple values
B) Only one value
C) No values
D) Both B and C

Answer:

D) Both B and C

Explanation:

A function in C can return only one value, or it can be a void function returning no value.

5. What does the ‘void’ keyword represent in a function?

A) The function takes no arguments
B) The function returns no value
C) The function is empty
D) The function has errors

Answer:

B) The function returns no value

Explanation:

The ‘void’ keyword indicates that the function doesn’t return any value.

6. How do you call a function named ‘display’ in C?

a) call display;
b) display.call();
c) display();
d) func display;

Answer:

c) display();

Explanation:

Functions are called by their name followed by parentheses.

7. If a function doesn’t explicitly return a value, what will its default return type be?

a) void
b) int
c) float
d) char

Answer:

a) void

Explanation:

If no return type is specified, it defaults to ‘void’ which means the function doesn’t return any value.

8. Which of the following is a valid function declaration?

A) void example() {}
B) function example() {}
C) void: example() {}
D) example function() {}

Answer:

A) void example() {}

Explanation:

The correct syntax for declaring a function in C is return_type function_name(parameters) { /* code */ }.

9. What is a recursive function?

A) A function that calls other functions
B) A function that can run indefinitely
C) A function that calls itself
D) A function with multiple parameters

Answer:

C) A function that calls itself

Explanation:

A recursive function is a function that calls itself in its definition.

10. Which of the following is true about function arguments passed by value?

A) The function works with the actual data.
B) Changes in the function do not affect the original data.
C) Changes in the function reflected in the original data.
D) The function cannot modify the arguments.

Answer:

B) Changes in the function do not affect the original data.

Explanation:

When arguments are passed by value, the function works with a copy of the data, not the actual data itself.

11. What is the purpose of the return statement in a function?

a) To terminate the function
b) To return control to the calling function
c) To return a value to the calling function
d) Both b and c

Answer:

d) Both b and c

Explanation:

The return statement is used to return control to the calling function and optionally to return a value.


Congratulations on completing the quiz! Functions are fundamental to efficient coding in C, and understanding them is key to becoming a proficient programmer. Keep practicing and exploring the nuances of functions in C.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top