Skip to content
main-logo
  • +91 637-050-2482
  • santuitreturns@gmail.com
Menu
Menu
  • Home
  • Income Tax
    • Income From Salary
    • Profit or gain from Business/Profession.
    • Capital Gain
    • Income From Other Sources
    • 80C to 80U
    • TDS & TCS
    • ITR FORMS
  • International Taxation
    • Transfer Pricing
    • Non-Resident Taxation
    • Foreign Tax Credit (FTC)
    • Model Tax Convention
    • Base Erosion and Profit Shifting (BEPS)
  • GST
  • Accounting
  • MCQs
    • NEET
    • NEET QUIZ TEST
    • NEET PG MCQ’s
    • NEET PG QUIZ TEST
    • Civil Engineering
    • Mechanical Engineering MCQs
    • CHSL EXAM
      • Logical Reasoning
  • Others
    • Job Tips
  • CA Courses
    • CA Inter/IPCC

10+ TOP C++ MCQs on Specialization

Posted on September 25, 2023

1. 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

View Answer

Answer: A

Explanation: 

 In the template specialization, it will make the template to be specific for some data types.

2. Which is similar to template specialization?

A. template
B. function overloading
C. function template overloading
D. overloading

View Answer

Answer: C

Explanation:

 function template overloading is similar to template specialization.

3. Which is called on allocating the memory for the array of objects?

A. destructor
B. constructor
C. method
D. class

View Answer

Answer: B

Explanation:

 When you allocate memory for an array of objects, the default constructor must be called to construct each object. If no default constructor exists, you’re stuck needing a list of pointers to objects.

4. What will be the output of the following C++ code?

    #include 
    using namespace std;
    template 
    inline T square(T x)
    {
        T result;
        result = x * x;
        return result;
    };
    template <>
    string square(string ss)
    {
        return (ss+ss);
    };

     int main()
    {
        int i = 2, ii;
        string ww("A");
        ii = square(i);
        cout << i << ": " << ii;
        cout << square(ww) << ":" << endl;
    }

A. 2: 4AA:
B. 2:4
C. AA
D. 2:4A

View Answer

Answer: A

Explanation:

 Template specialization is used when a different and specific implementation is to be used for a specific data type. In this program, We are using integer and character.

5. What will be the output of the following C++ code?
    #include <iostream> 
    using namespace std;
    template <typename T = float, int count = 3>
    T multIt(T x)
    {
        for(int ii = 0; ii < count; ii++)
        {
            x = x * x;
        }
        return x;
    };
    int main()
    {
        float xx = 2.1;
        cout << xx << ": " << multIt<>(xx) << endl;
    }

View Answer

Answer: C

Explanation: AWT stands for Abstract Window Toolkit, it is used by applets to interact with the user.

A. 2.1
B. 378.228
C. 2.1: 378.228
D. 376

View Answer

Answer: C

Explanation:

 In this program, We specify the type in the template function. We need to compile this program by adding -std=c++0x.

6. What will be the output of the following C++ code?
    #include <iostream>
    using namespace std;
    template <class T>
    class XYZ
    {
        public:
        void putPri();
        static T ipub;
        private:
        static T ipri; 
    };
    template <class T>
      void XYZ<T>::putPri()
    {
        cout << ipri++ << endl;
    }
   template <class T> T XYZ<T>::ipub = 1;
    template <class T> T XYZ<T>::ipri = 1.2;
    int main()
    {
       XYZ<int> a;
        XYZ<float> b;
        a.putPri();
        cout << a.ipub << endl;
        b.putPri();
    }

A. 1

B. 1.2

C.1
1.2

D.1
1
1.2

 

View Answer

Answer: D

Explanation:

In this program, We are passing the value of specified type and printing it by specialization.

7. What will be the output of the following C++ code?
    #include <iostream>
    #include  <string>
    #include  <cstring>
    using namespace std;
    template <class type>
    type MyMax(const type Var1, const type Var2)
    {
        cout << "no specialization";
        return Var1 < Var2 ? Var2 : Var1;
    }
    template <>
    const char *MyMax(const char *Var1, const char *Var2)
    {
        return (strcmp(Var1, Var2)<0) ? Var2 : Var1;
    }
    int main()
    {
        string Str1 = "class", Str2 = "template";
        const char *Var3 = "class";
        const char *Var4 = "template";
        const char *q = MyMax(Var3, Var4);
        cout << q << endl;
        return 0;
    }

A. template
B. class
C. no specialization
D. templateclass

View Answer

Answer: C

Explanation:

 In this program, We are using the non-type template parameter to increment the value in the function template.

8. How many types of specialization are there in c++?

A. 1
B. 2
C. 3
D. 4

View Answer

Answer: B

Explanation:

 There are two types of specialization. They are full specialization and partial specialization.

9. What is another name of full specialization?

A. explicit specialization
B. implicit specialization
C. function overloading template
D. overloading template

View Answer

Answer: A

Explanation:

 explicit specialization is another name of full specialization.

    You May Also Like...

  • 10+ TOP C++ MCQs on OOPs Concept – 2
  • 10+ TOP C++ MCQs on OOPs Concept – 3
  • 10+ TOP C++ MCQs on Integer Types
  • 10+ TOP C++ MCQs on Floating Point Types
  • 10+ TOP C++ MCQs on References – 2
  • 10+ TOP C++ MCQs on References – 3
  • 10+ TOP C++ MCQs on Objects
  • 10+ TOP C++ MCQs on Operator Functions

Leave a Reply Cancel reply

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

Quick Links

  • Home
  • About Us
  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Contact Us

Categories

  • Income Tax
  • International Taxation
  • GST
  • MCQs
  • Others
  • CA Courses

Latest Posts

  • Five changes in ITR forms of FY 2024-25 (AY 2025-26)
  • Form 10-IEA: Option to Choose Old Tax Regime
  • What is Section 54EC of the Income Tax Act?
  • What is Section 54F of the Income Tax Act?
©2025 Online Solves. All rights Reserved | Developed by AlgoPage IT Solutions Pvt. Ltd.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT