I am not able to understand the output of the below code:-
#include <iostream>
using namespace std;
template <typename T>
void fun(const T&x){
 static int count = 0;
 cout << "x = " << x << " count = " << count << endl;
 ++count;
 return;
}
int main(){
 fun(1);
 fun('A');
 fun(1.1);
 fun(2.2);
 return 0;
}
Output:-
x = 1 count = 0
x = A count = 0
x = 1.1 count = 0
x = 2.2 count = 1
If value of static variable count is being reassigned to 0 whenever the function is called, then why its coming 1 when the function is being called fourth time. And another thing , can we not pass "T x" directly instead of "const T&x"?
 
     
     
    