C++ examples for Function:Global Variable
Using a global variable to count calls to print().
#include <string> #include <iostream> using std::string; int print_count = 0; void print(const string& s) { std::cout << s << std::endl; ++print_count; // ADDED } void print_this(const string& s) { print(s);//from w w w.j a v a2 s . c o m } void print_that(const string& s) { print(s); } int main() { print_this("this"); print_that("that"); std::cout << "The print() function has been called a total of " << print_count << " times. " << std::endl; }