C++ Functions MCQ Quiz - MCQ Questions and Answers

Welcome to "C++ Functions MCQ Quiz - MCQ Questions and Answers," a quiz designed to test and enhance your understanding of functions in C++. Functions are a cornerstone of C++ programming, essential for writing clean, modular, and efficient code. 

This quiz comprises 20 multiple-choice questions that range from basic to advanced levels, covering various aspects of function declaration, definition, scope, and usage in C++. Whether you're a student preparing for exams, a developer looking to refresh your knowledge, or an enthusiast eager to challenge your understanding of C++ functions, this quiz is a perfect tool. Get ready to dive into the intricacies of C++ functions and assess your programming prowess!

1. What is a function in C++?

a) A block of code that executes when the program starts
b) A named unit of code that can be invoked from other parts of the program
c) A variable declaration
d) A class member

2. How do you define a function in C++?

a) dataType functionName {parameterList}
b) functionName(dataType parameterList)
c) dataType functionName(parameterList) {body}
d) functionName: dataType(parameterList) {body}

3. What is function overloading in C++?

a) Changing the return type of a function
b) Creating a function inside another function
c) Having multiple functions with the same name but different parameters
d) Calling a function multiple times

4. What is the main difference between a function and a method in C++?

a) A function cannot return a value, while a method can
b) A function is defined inside a class, while a method is not
c) A method is a function defined inside a class
d) There is no difference

5. What is a default argument in a function in C++?

a) An argument that is always required
b) An argument that the function uses if no corresponding argument is passed
c) The first argument in a function
d) An argument that defaults to zero

6. What is a 'const' member function in C++?

a) A function that can modify the object it is called on
b) A function that cannot change any class member variables
c) A function that is always called first
d) A constructor function

7. What is the return type of a constructor in C++?

a) void
b) The type of the class
c) It has no return type
d) int

8. Which of the following is true about inline functions in C++?

a) They are always faster than regular functions
b) The compiler may ignore the inline request
c) They cannot have a loop
d) They are defined outside the class

9. What is recursion in C++?

a) A loop in a function
b) A class calling another class
c) A function calling itself
d) Overloading a function

10. What is a static function in C++?

a) A function that can be called without creating an object
b) A function that retains its values between calls
c) A function that cannot be changed
d) A member function that is called automatically

11. How are function arguments passed in C++ by default?

a) By reference
b) By value
c) By pointer
d) By constant reference

12. What is the purpose of a function prototype in C++?

a) To define a function
b) To declare a function before its usage
c) To initialize function variables
d) To terminate a function

13. What are variadic functions in C++?

a) Functions that can take a variable number of arguments
b) Functions that return variable values
c) Functions that vary in return type
d) Functions that can be called in various ways

14. What is the significance of the 'main' function in C++?

a) It indicates the end of the program
b) It is the first function that gets called when a program starts
c) It is used to define methods
d) It is a special class constructor

15. How do you define a function that returns a reference in C++?

a) dataType& functionName(parameters)
b) &dataType functionName(parameters)
c) dataType functionName&(parameters)
d) dataType functionName(parameters)&

16. What is a lambda function in C++?

a) A function used only in loops
b) An anonymous function
c) A predefined function in the standard library
d) A recursive function

17. What happens when a function is declared as 'friend' in a class?

a) It can access all private and protected members of the class
b) It becomes a member function of the class
c) It can only be called by other member functions
d) It is automatically inlined

18. What is the correct syntax for a function pointer in C++?

a) dataType (*functionName)(parameters)
b) dataType *functionName(parameters)
c) dataType functionName*(parameters)
d) *dataType functionName(parameters)

19. What is meant by default parameters in C++ functions?

a) Parameters that are optional and have default values
b) Parameters that are always required
c) The first parameter in a function
d) Parameters that default to NULL

20. What is the use of the 'return' statement in C++?

a) To exit the program
b) To return control to the calling function
c) To print a value
d) To terminate a loop

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare