#include<iostream>
using namespace std;
void callMe()
{
int count=0;
cout<<"I am called "<<++count<<" times!\n";
}
int main()
{
callMe();
callMe();
callMe();
callMe();
return 0;
}
In this case, the output will be
I am called 1 times! I am called 1 times! I am called 1 times! I am called 1 times!
Instead, I want the output printed as
I am called 1 times! I am called 2 times! I am called 3 times! I am called 4 times!
I hope that the following code snippet will solve your issue!
Here the static variable will retain its value and it will print the count incremented each time!