CPP

CPP

Template Arguments to Specify Policy Usage has 9 Questions
What is meant by template parameter?

It can be used to pass a type as argument
It can be used to evaluate a type.
It can of no return type
None of the mentioned
Which keyword can be used in template?

class
typename
both a & b
function
What is the validity of template parameters?

inside that block only
inside the class
whole program
any of the mentioned
hat is the output of this program?
  1.    #include 
  2.    using namespace std;
  3.    template <class T, int N>
  4.    class mysequence 
  5.    {
  6.        T memblock [N];
  7.        public:
  8.        void setmember (int x, T value);
  9.        T getmember (int x);
  10.    };
  11.    template <class T, int N>
  12.    void mysequence<T,N> :: setmember (int x, T value) 
  13.    {
  14.        memblock[x] = value;
  15.    }
  16.    template <class T, int N>
  17.    T mysequence<T,N> :: getmember (int x) 
  18.    {
  19.        return memblock[x];
  20.    }
  21.    int main () 
  22.    {  
  23.        mysequence <int, 5> myints;
  24.        mysequence <double, 5> myfloats;
  25.        myints.setmember (0, 100);
  26.        myfloats.setmember (3, 3.1416);
  27.        cout << myints.getmember(0) << '\n';
  28.        cout << myfloats.getmember(3) << '\n';
  29.        return 0;
  30.    }

100
3.1416
100 3.1416
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     template <class T>
  4.     T max (T& a, T& b) 
  5.     {
  6.         return (a>b?a:b);
  7.     }
  8.     int main () 
  9.     {
  10.         int i = 5, j = 6, k;
  11.         long l = 10, m = 5, n;
  12.         k = max(i, j);
  13.         n = max(l, m);
  14.         cout << k << endl;
  15.         cout << n << endl;
  16.         return 0;
  17.     }

6
6 ????10
5 ????10
6 ????5
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     template <class type>
  4.     class Test
  5.     {
  6.         public:
  7.         Test()
  8.         {
  9.         };
  10.         ~Test()
  11.         {  
  12.         };
  13.         type Funct1(type Var1)
  14.         {
  15.             return Var1;
  16.         }
  17.         type Funct2(type Var2)
  18.         {
  19.             return Var2;
  20.         }
  21.     };
  22.     int main()
  23.     {
  24.         Test<int> Var1;
  25.         Test<double> Var2;
  26.         cout << Var1.Funct1(200);
  27.         cout << Var2.Funct2(3.123);
  28.         return 0;
  29.     }

100
200
3.123
2003.123
Why we use :: template-template parameter?

binding
rebinding
both a & b
none of these
Which parameter is legal for non-type template?

pointer to member
object
class
none of the mentioned
Which of the things does not require instantiation?

functions
non virtual member function
member class
all of the mentioned