C++ interview questions part 57

C++ interview questions part 57

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Why we use :: template-template parameter?

Correct Answer is : Interface to sequence container

2. Which parameter is legal for non-type template?

Correct Answer is : all of the mentioned

3. Which of the things does not require instantiation?

Correct Answer is : 63

4. Which of the following is used for generic programming?

Correct Answer is : 55

5. Which of the following is correct about templates?

Correct Answer is : 100 40 30 25

6. What is the output of the following C++ code? #include using namespace std; template void fun(const T&x) { static int count = 0; cout << "x = " << x << " count = " << count; ++count; return; }   int main() { fun (1); cout << endl; fun(1); cout << endl; fun(1.1); cout << endl; return 0; }

Correct Answer is : 5

7. What is the output of the following C++ function? #include using namespace std; template T max(T x, T y) { return (x > y)? x : y; } int main() { cout << max(3, 7) << std::endl; cout << max(3.0, 7.0) << std::endl; cout << max(3, 7.0) << std::endl; return 0; }

Correct Answer is : 15

8. What is the output of the following C++ code? #include using namespace std; template class Test { private: T val; public: static int count; Test() { count++; } }; template int Test::count = 0; int main() { Test a; Test b; Test c; cout << Test::count << endl; cout << Test::count << endl; return 0; }

Correct Answer is : LIFO

9. What is the output of the following C++ code? #include #include using namespace std; template class A { T x; U y; };   int main() { A a; A b; cout << sizeof(a) << endl; cout << sizeof(b) << endl; return 0; }

Correct Answer is : operator<

10. What is the output of the following C++ code? #include #include using namespace std; template class A { T x; U y; V z; };   int main() { A a; A b; cout << sizeof(a) << endl; cout << sizeof(b) << endl; return 0; }

Correct Answer is : 5

11. What is the output of the following C++ code? #include using namespace std; template int arrMin(T arr[], int n) { int m = max; for (int i = 0; i < n; i++) if (arr[i] < m) m = arr[i];   return m; }   int main() { int arr1[] = {10, 20, 15, 12}; int n1 = sizeof(arr1)/sizeof(arr1[0]);   char arr2[] = {1, 2, 3}; int n2 = sizeof(arr2)/sizeof(arr2[0]);   cout << arrMin(arr1, n1) << endl; cout << arrMin(arr2, n2); return 0; }

Correct Answer is : both vector & dequeue

12. What is the output of the following C++ code? #include using namespace std; template T max (T &a, T &b) { cout << "Template Called "; return (a > b)? a : b; }   template int max (int &a, int &b) { cout << "Called "; return (a > b)? a : b; }   int main () { int a = 10, b = 20; cout << max (a, b); }

Correct Answer is : back

13. What is the output of the following C++ code? #include using namespace std; template struct funStruct { static const int val = 2*funStruct::val; };   template struct funStruct<0> { static const int val = 1 ; };   int main() { cout << funStruct<10>::val << endl; return 0; }

Correct Answer is : 54321

14. What are the tuples in C++?

Correct Answer is : a contains: 200 200 200 200 200b contains: 100 100 100

15. Which of the following is correct about tuples?

Correct Answer is : Both 110 & 220

16. Which header file is required to use tuples in your program?

Correct Answer is : 0 1 2 3 4

17. Which of the following is the correct way of declaring a tuple?

Correct Answer is : 2.72 12.15 72.25

18. Which of the following function is used to initialize a tuple?

Correct Answer is : Using Double linked list

19. What is the output of the following C++ code? #include #include #include using namespace std; int main() { tuple tp = {"Hello", 1, 's'}; return 0; }

Correct Answer is : Array

20. What is the output of the following C++ code? #include #include #include using namespace std; int main() { tuple tp; tp = make_tuple(4, '1', "Hello"); return 0; }

Correct Answer is : Uni-directional

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon