ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
template <typename T> struct Is     { static const int v = 0; };
template <>           struct Is<int> { static const int v = 1; };
template <typename T> struct Is<T*>  { static const int v = 2; };
int main() {
    cout << Is<int>::v << Is<int*>::v << Is<double>::v << Is<const int>::v;
}
  1. A. 1201
  2. B. 1000
  3. C. 1200
  4. D. 1202

Correct answer: C. 1200

int uses the full specialisation, int* matches the partial specialisation for pointers, and double falls to the primary template. const int is a different type from int, so it also uses the primary template.

More OOP with C++ and Java questions

Exams that ask this topic