CPP

CPP

Simple String Template has 11 Questions

What is a template?

A template is a formula for creating a generic class
A template is used to manipulate the class
A template is used for creating the attributes
none of the mentioned
What is a template?

A template is a formula for creating a generic class
A template is used to manipulate the class
A template is used for creating the attributes
none of the mentioned
Pick out the correct statement about string template.

It is used to replace a string.
It is used to replace a string with another string at runtime.
It is used to delete a string.
none of the mentioned
How to declare a template?

tem
temp
template<>
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 = 4, ii;
  18.         string ww("A");
  19.         ii = square<int>(i);
  20.         cout << i << ii;
  21.         cout << square<string>(ww) << endl;
  22.     }

416AA
164AA
AA416
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     template <typename T, typename U>
  4.     void squareAndPrint(T x, U y)
  5.     {
  6.         cout << x << x * x << endl;
  7.         cout << y << " " << y * y << endl;
  8.     };
  9.     int main()
  10.     {
  11.         int ii = 2;
  12.         float jj = 2.1;
  13.         squareAndPrint<int, float>(ii, jj);
  14.     }

23 2.1 4.41
24 2.1 4.41
24 2.1 3.41
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     template<typename T>
  5.     void print_mydata(T output)
  6.     {
  7.         cout << output << endl;
  8.     }
  9.     int main()
  10.     {
  11.         double d = 5.5;
  12.         string s("Hello World");
  13.         print_mydata( d );
  14.         print_mydata( s );
  15.         return 0;
  16.     }

5.5 Hello World
5.5
Hello World
none of the mentioned
How many types of templates are there in c++?

1
2
3
4
Which are done by compiler for templates?

type-safe
portability
code elimination
all of the mentioned
What may be the name of the parameter that the template should take?

same as template
same as class
same as function
none of the mentioned
How many parameters are legal for non-type template?

1
2
3
4