C++ Programming MCQ (Multiple Choice Questions) - SchoolingAxis

C++ Programming MCQ (Multiple Choice Questions)

 Que- How many types of templates are there in c++? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Which are done by compiler for templates? 

a. type-safe 

b. portability 

c. code elimination 

d. prototype 


Answer- type-safe 


Que- What may be the name of the parameter that the template should take? 

a. same as template 

b. same as class 

c. same as function 

d. same as member 


Answer- same as template 


Que- How many parameters are legal for non-type template? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 4 


Que- What is a function template? 

a. creating a function without having to specify the exact type 

b. creating a function with having an exact type 

c. creating a function without having blank spaces 

d. creating a function without class 


Answer- creating a function without having to specify the exact type 


Que- Which is used to describe the function using placeholder types? 

a. template parameters 

b. template type parameters 

c. template type 

d. type parameters 


Answer- template type parameters 


Que- Pick out the correct statement. 

a. you only need to write one function, and it will work with many different types 

b. it will take a long time to execute 

c. duplicate code is increased 

d. it will take a long time to execute & duplicate code is increased 


Answer- you only need to write one function, and it will work with many different types 


Que- What can be passed by non-type template parameters during compile time? 

a. int 

b. float 

c. constant expression 

d. string 


Answer- constant expression 


Que- From where does the template class derived? 

a. regular non-templated C++ class 

b. templated class 

c. regular non-templated C++ class or templated class 

d. main function 


Answer- regular non-templated C++ class or templated class 


Que- What are Templates in C++? 

a. A feature that allows the programmer to write generic programs 

b. A feature that allows the programmer to write specific codes for a problem 

c. A feature that allows the programmer to make program modular 

d. A feature that does not add any power to the language 


Answer- A feature that allows the programmer to write generic programs 


Que- In how many ways templates concept can be used? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- What is the difference between normal function and template function? 

a. The normal function works with any data types whereas template function works with specific types only 

b. Template function works with any data types whereas normal function works with specific types only 

c. Unlike a normal function, the template function accepts a single parameter 

d. Unlike the template function, the normal function accepts more than one parameters 


Answer- Template function works with any data types whereas normal function works with specific types only 


Que- Templates simulate which of the following feature? 

a. Polymorphism 

b. Abstraction 

c. Encapsulation 

d. Inheritance 


Answer- Polymorphism 


Que- Which keyword is used for the template? 

a. Template 

b. template 

c. Temp 

d. temp 


Answer- template 


Que- What is the correct syntax of defining function template/template functions? 

a. template <class T> void(T a){cout<<a;} 

b. Template <class T> void(T a){cout<<a;} 

c. template <T> void(T a){cout<<a;} 

d. Template <T> void(T a){cout<<a;} 


Answer- template <class T> void(T a){cout<<a;} 


Que- What are Templates in C++? 

a. A feature that allows the programmer to write generic programs 

b. A feature that allows the programmer to write specific codes for a problem 

c. A feature that allows the programmer to make program modular 

d. A feature that does not add any power to the language 


Answer- A feature that allows the programmer to write generic programs 


Que- In how many ways templates concept can be used? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- What is the difference between normal function and template function? 

a. The normal function works with any data types whereas template function works with specific types only 

b. Template function works with any data types whereas normal function works with specific types only 

c. Unlike a normal function, the template function accepts a single parameter 

d. Unlike the template function, the normal function accepts more than one parameters 


Answer- Template function works with any data types whereas normal function works with specific types only 


Que- Templates simulate which of the following feature? 

a. Polymorphism 

b. Abstraction 

c. Encapsulation 

d. Inheritance 


Answer- Polymorphism 


Que- Which keyword is used for the template? 

a. Template 

b. template 

c. Temp 

d. temp 


Answer- template 


Que- What is the correct syntax of defining function template/template functions? 

a. template <class T> void(T a){cout<<a;} 

b. Template <class T> void(T a){cout<<a;} 

c. template <T> void(T a){cout<<a;} 

d. Template <T> void(T a){cout<<a;} 


Answer- template <class T> void(T a){cout<<a;} 


Que- What is the syntax of class template? 

a. template <paramaters> class declaration 

b. Template <paramaters> class declaration 

c. temp <paramaters> class declaration 

d. Temp <paramaters> class declaration 


Answer- template <paramaters> class declaration 


Que- What is meant by the template parameter? 

a. It can be used to pass a type as an argument 

b. It can be used to evaluate a type 

c. It can of no return type 

d. It can be used to delete a type 


Answer- It can be used to pass a type as an argument 


Que- Which keyword can be used in template? 

a. class 

b. typename 

c. both class & typename 

d. function 


Answer- both class & typename 


Que- What is the validity of template parameters? 

a. inside that block only 

b. inside the class 

c. whole program 

d. inside the main class 


Answer- inside that block only 


Que- Why we use :: template-template parameter? 

a. binding 

b. rebinding 

c. both binding & rebinding 

d. reusing 


Answer- both binding & rebinding 


Que- Which parameter is legal for non-type template? 

a. pointer to member 

b. object 

c. class 

d. baseclass 


Answer- pointer to member 


Que- Which of the things does not require instantiation? 

a. functions 

b. non virtual member function 

c. member class 

d. all of the mentioned 


Answer- all of the mentioned 


Que- What is meant by template specialization? 

a. It will have certain data types to be fixed 

b. It will make certain data types to be dynamic 

c. Certain data types are invalid 

d. It will make all data types to be dynamic 


Answer- It will have certain data types to be fixed 


Que- Which is similar to template specialization? 

a. template 

b. function overloading 

c. function template overloading 

d. overloading 


Answer- function template overloading 


Que- Which is called on allocating the memory for the array of objects? 

a. destructor 

b. constructor 

c. method 

d. class 


Answer- constructor 


Que- How many types of specialization are there in c++? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- What is another name of full specialization? 

a. explicit specialization 

b. implicit specialization 

c. function overloading template 

d. overloading template 


Answer- explicit specialization 


Que- Which is dependant on template parameter? 

a. base class 

b. abstract class 

c. method 

d. static class 


Answer- base class

Previous Post Next Post

Responsive Ad