1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
int count_calls() {
// initialization occurs only once when program is loaded
static int counter = 0;
return ++counter; // pre-increments then returns
}
int main() {
count_calls();
count_calls();
cout << "number of calls: "<< count_calls() << endl;
return 0;
}
Enter to Rename, Shift+Enter to Preview