fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void test() {
  5. static int i;
  6. cout << "Value in the beginning: " << i << endl;
  7. i = 4;
  8. cout << "Value in the middle: " << i << endl;
  9. i++;
  10. cout << "Value in the end: " << i << endl;
  11. }
  12.  
  13. int main() {
  14. cout << "Static variables demo by FreeNickname." << endl;
  15. for (int i = 0; i < 3; ++i)
  16. test();
  17. return 0;
  18. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Static variables demo by FreeNickname.
Value in the beginning: 0
Value in the middle: 4
Value in the end: 5
Value in the beginning: 5
Value in the middle: 4
Value in the end: 5
Value in the beginning: 5
Value in the middle: 4
Value in the end: 5