From where does the template class derived?
What can be passed by non-type template parameters during compile time?
What is the output of this program?
1. #include2. using namespace std; 3. template 4. void loopIt(T x) 5. { 6. int count = 3; 7. T val[count]; 8. for (int ii=0; ii < count; ii++) 9. { 10. val[ii] = x++; 11. cout << val[ii] << endl; 12. } 13. }; 14. int main() 15. { 16. float xx = 2.1; 17. loopIt(xx); 18. }
a) 2.1
b) 3.1
c) 3.2
d) 2.1
3.1
4.1
What is the output of this program?
1. #include2. using namespace std; 3. template 4. inline T square(T x) 5. { 6. T result; 7. result = x * x; 8. return result; 9. }; 10. int main() 11. { 12. int i, ii; 13. float x, xx; 14. double y, yy; 15. i = 2; 16. x = 2.2; 17. y = 2.2; 18. ii = square(i); 19. cout << i << " " << ii << endl; 20. yy = square(y); 21. cout << y << " " << yy << endl; 22. }
a) 2 4
2.2 4.84
b) 2 4
c) error
d) runtime error
What is the output of this program?
1. #include2. using namespace std; 3. template 4. class TestVirt 5. { 6. public: 7. virtual type TestFunct(type Var1) 8. { 9. return Var1 * 2; 10. } 11. }; 12. int main() 13. { 14. TestVirt Var1; 15. cout << Var1.TestFunct(100) << endl; 16. return 0; 17. }