Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std; 
template <typename T>
void fun(const T&x)
{
    static int count = 0;
    cout << "x = " << x << " count = " << count;
    ++count;
    return;
}
 
int main()
{
    fun<int> (1); 
    cout << endl;
    fun<int>(1); 
    cout << endl;
    fun<double>(1.1);
    cout << endl;
    return 0;
}

A. x = 1 count = 0
x = 1 count = 1
x = 1.1 count = 0

B. x = 1 count = 0
x = 1.0 count = 1.0
x = 1.1 count = 0

C. x = 1.0 count = 0.0
x = 1 count = 1
x = 1.1 count = 0

D. x = 1.0 count = 0.0
x = 1.0 count = 1.0
x = 1.1 count = 0.0

Answer: Option A


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it