MCQ Bank
In a function template template<typename T>, what does T represent?
- A) Function return value
- B) Type parameter
- C) Built-in type
- D) Non-type parameter
When is a class template instantiated?
- A) At runtime
- B) At compile time
- C) When linked
- D) When declared
What is the purpose of a generic algorithm in C++?
- A) To avoid the use of pointers
- B) To create run-time polymorphism
- C) To make algorithms independent of data structures
- D) To handle integer data only
What is the purpose of explicit specialization in templates?
- A) To avoid the use of templates
- B) To simplify the template syntax
- C) To handle specific data types that the template cannot handle successfully
- D) To improve runtime performance
Which of the following is true about friend functions in template classes?
- A) They can access private and protected members of the class.
- B) They must be defined inside the class.
- C) They are inherited by derived classes.
- D) They can only access public members of the class.
The partial specialization pattern T* says that this specialization is to be used for every _______.
- A) Virtual type
- B) Pointer type
- C) Meta type
- D) Data type
Which of the following is an example of general template?
- A) template<class T, class U>
- B) template<int , float , int>
- C) template<class T, float>
- D) template<class T, class U, int>
Which of the following is the correct syntax for a function template in C++?
- A) template<class T> void func(T a);
- B) template void func<class T>(T a);
- C) func<class T>(T a);
- D) template<type T> func(T a);
What does a C++ template allow you to do?
- A) None of the given
- B) Write functions or classes that can operate with different data types
- C) Define multiple main functions in a program
- D) Create new data types dynamically at runtime
To accept two type parameters, __________ is written.
- A) template<typename T, typename U>
- B) template<class T U>
- C) template<typename T U>
- D) template<class T, U>
Which of the following creates the strongest relationship between two objects?
- A) Association
- B) Composition
- C) Aggregation
- D) Inheritance
Which of the following is a weak relationship?
- A) Inheritance
- B) Association
- C) Composition
- D) Aggregation
Which of the following is correct feature that is used to make basic operators like +, - , * and / etc. to work with user defined types?
- A) type loading
- B) inheritance
- C) abstraction
- D) operator overloading
In C++, if new operator is used, when is the constructor called?
- A) Constructor is called to allocate memory
- B) Depends on code
- C) Before the allocation of memory
- D) After the allocation of memory
Suppose c1, c2, and c3 are the objects of the Complex class and we overloaded the + operator. c3 = c1 + c2; In this statement, ___________ object will be passed as argument when + operator is called.
- A) c1 and c2
- B) c2
- C) c3
- D) c1
Static data members are shared by _____ of the class.
- A) Protected data members
- B) All types of data members
- C) Public data members
- D) Private data members
Which of the following best defines static data members of a class?
- A) Data member with global scope
- B) Data member which is common to all the objects of a class
- C) Data member which is allocated for each object separately
- D) Data member which is common to all the classes in a program
When an object of a class is the data member of another class, it is called as _________.
- A) aggregation
- B) inheritance
- C) composition
- D) Association
What is the purpose of new operator?
- A) Used as return type when an object is created
- B) Used to declare any new thing in a program
- C) Allocates memory for an object or array
- D) Allocates memory for an object or array and returns a particular pointer
Overloading binary operator as a member function of a class requires ____________ argument/s.
- A) 1
- B) 3
- C) 0
- D) 2