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.
#include<iostream> #include<stdlib.h> 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; } |
chevron_right
filter_none
(A)
6 12
(B)
2 8
(C) Compiler Error: There can not be more than one template arguments.
(D)
8 8
Answer: (B)
Explanation: Since count is static, it is not counted in sizeof.
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C++ | Templates | Question 1
- C++ | Templates | Question 2
- C++ | Templates | Question 4
- C++ | Templates | Question 6
- C++ | Templates | Question 10
- C++ | Templates | Question 8
- C++ | Templates | Question 9
- C++ | Templates | Question 10
- C++ | Templates | Question 3
- Templates and Default Arguments
- A comma operator question
- C | Input and Output | Question 13
- C | Input and Output | Question 2
- C | Input and Output | Question 3
- C | Operators | Question 2
- C | Operators | Question 3
- C | Operators | Question 4
- C | Input and Output | Question 4
- C | Loops & Control Structure | Question 1
- C | Arrays | Question 1

