#include <iostream>using namespace std; void test() { static int i; cout << "Value in the beginning: " << i << endl; i = 4; cout << "Value in the middle: " << i << endl; i++; cout << "Value in the end: " << i << endl;} int main() { cout << "Static variables demo by FreeNickname." << endl; for (int i = 0; i < 3; ++i) test(); return 0;}
Standard input is empty
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
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!