Example:
// ConsoleApplication1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; void sub(); int _tmain(int argc, _TCHAR* argv[]) { cout << "First run - " << endl; sub(); cout << "Second run - " << endl; sub(); system("PAUSE"); return 0; } void sub(){ int i; static int statici; cout << "before assign in sub()" << endl; cout << "i = " << i << endl; cout << "statici = " << statici << endl; i = 1; statici = 2; cout << "after assign in sub()" << endl; cout << "i = " << i << endl; cout << "statici = " << statici << endl; cout << endl; }
![Example of static variable Example of static variable](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg03F9u8HyPVBXrJ2usSI7yabNm9K5wTXQO1AkTut0kwJzZp399EXfoTZhS101sZR5xZauvTVqut-UDHQS9aDJzdaBppnPIn5TTkLhpJfmJm4ZN72wQ3Ibagm92G5oLRYV7lUfLfg2yWg0/s400/static+variable.png)
No comments:
Post a Comment