Skip to content
Related Articles

Related Articles

Improve Article

C++ | Templates | Question 5

  • Last Updated : 28 Jun, 2021

Output of following program? Assume that the size of char is 1 byte and size of int is 4 bytes, and there is no alignment done by the compiler.

using namespace std;
template<class T, class U>
class A  {
    T x;
    U y;
    static int count;
int main()  {
   A<char, char> a;
   A<int, int> b;
   cout << sizeof(a) << endl;
   cout << sizeof(b) << endl;
   return 0;





(C) Compiler Error: There can not be more than one template arguments.


Answer: (B)

Explanation: Since count is static, it is not counted in sizeof.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :