undefined

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Static Variables and Functions - Part II

#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;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content