Advertisement
Felanpro

Static Variables

Jan 13th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. //Static Variables
  2. #include "stdafx.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. void counter()
  7. {
  8.     static int x = 0;
  9.  
  10.     cout << "This function has been called " << ++x << " times!" << endl;
  11. }
  12.  
  13. int main()
  14. {
  15.    
  16.     counter();
  17.     counter();
  18.     counter();
  19.  
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement