CPP

CPP

Specialization has 9 Questions
What is meant by template specialization?

It will have certain data types to be fixed.
It will make certain data types to be dynamic.
Certain data types are invalid
None of the mentioned
Which is similar to template specialization?

template
function overloading
function template overloading
None of the mentioned
Which is called on allocating the memory for array of objects?

destructor
constructor
method
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     template <class T>
  4.     inline T square(T x)
  5.     {
  6.         T result;
  7.         result = x * x;
  8.         return result;
  9.     };
  10.     template <>
  11.     string square<string>(string ss)
  12.     {
  13.         return (ss+ss);
  14.     };
  15.     int main()
  16.     {
  17.         int i = 2, ii;
  18.         string ww("A");
  19.         ii = square<int>(i);
  20.         cout << i << ": " << ii;
  21.         cout << square<string>(ww) << ":" << endl;
  22.     }

2:4AA
2:4
AA
2:4A
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     template <class T>
  4.     class XYZ
  5.     {
  6.         public:
  7.         void putPri();
  8.         static T ipub;
  9.         private:
  10.         static T ipri; 
  11.     };
  12.     template <class T>
  13.     void XYZ<T>::putPri()
  14.     {
  15.         cout << ipri++ << endl;
  16.     }
  17.     template <class T> T XYZ<T>::ipub = 1;
  18.     template <class T> T XYZ<T>::ipri = 1.2;
  19.     int main()
  20.     {
  21.         XYZ<int> a;
  22.         XYZ<float> b;
  23.         a.putPri();
  24.         cout << a.ipub << endl;
  25.         b.putPri();
  26.     }

1
1.2
1 ????1.2
1 ????1 ????1.2
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     template<class T = float, int i = 5> class A
  4.     {
  5.         public:
  6.         A();
  7.         int value;
  8.     };
  9.     template<> class A<> 
  10.     { 
  11.         public: A(); 
  12.     };
  13.     template<> class A<double, 10>
  14.     { 
  15.         public: A(); 
  16.     };
  17.     template<class T, int i> A<T, i>::A() : value(i)
  18.     {
  19.         cout << value;
  20.     }
  21.     A<>::A() 
  22.     {
  23.         cout << "default";
  24.     }
  25.     A<double, 10>::A() 
  26.     {
  27.         cout << "10" << endl;
  28.     }
  29.     int main() 
  30.     {
  31.         A<int, 6> x;
  32.         A<> y;
  33.         A<double, 10> z;
  34.     }

6
10
6default10
None of the mentioned
How many types of specialization are there in c++?

1
2
3
4
What is other name of full specialization?

explicit specialization
implicit specialization
function overloading template
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     template <class type>
  6.     type MyMax(const type Var1, const type Var2)
  7.     {
  8.         cout << "no specialization";
  9.         return Var1 < Var2 ? Var2 : Var1;
  10.     }
  11.     template <>
  12.     const char *MyMax(const char *Var1, const char *Var2)
  13.     {
  14.         return (strcmp(Var1, Var2)<0) ? Var2 : Var1;
  15.     }
  16.     int main()
  17.     {
  18.         string Str1 = "class", Str2 = "template";
  19.         const char *Var3 = "class";
  20.         const char *Var4 = "template";
  21.         const char *q = MyMax(Var3, Var4);
  22.         cout << q << endl;
  23.         return 0;
  24.     }

template
class
no specialization
None of the mentioned