What Is The Output Of Following Program P Pre Langcpp #417
What is the output of following program? </p> <pre><code class="language-cpp"> template <typename T> void test(const T&x) { static int count = 0; cout << "x = " << x << " count = " << count << endl; ++count; return; } void main() { test<int> (2); test<int>(2); test<double>(2.2); } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 OOps Classes - Object Oriented Programming MCQ: Template Class - Quiz No.2.
What is the output of following program?
template <typename T> void test(const T&x) { static int count = 0; cout << "x = " << x << " count = " << count << endl; ++count; return; } void main() { test<int> (2); test<int>(2); test<double>(2.2); }
x = 2 count = 0 x = 2.2 count = 0 x = 2.2 count = 0
x = 2 count = 0 x = 2 count = 0 x = 2.2 count = 0
x = 2 count = 0 x = 2 count = 1 x = 2.2 count = 0
x = 2 count = 0 x = 2 count = 1 x = 2.2 count = 2