Mega Code Archive

 
Categories / C++ / Language
 

Static function variable

#include <iostream> using namespace std; void printMessage(void);   int main () {    char choice;    do {       cout << "Enter Q to quit, any other character to continue: ";       cin >> choice;       if (choice == 'Q')          cout << "Input stopped";       else          printMessage();        } while (choice != 'Q');    return 0; } void printMessage (void) {    static int times = 0;    times++;    cout << "This function called " << times << " times\n"; }