mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-09 13:26:34 +08:00
update
This commit is contained in:
24
basic_content/static/static_demo.cpp
Normal file
24
basic_content/static/static_demo.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// the use of static Static
|
||||
// variables in a Function
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
void demo()
|
||||
{
|
||||
// static variable
|
||||
static int count = 0;
|
||||
cout << count << " ";
|
||||
|
||||
// value is updated and
|
||||
// will be carried to next
|
||||
// function calls
|
||||
count++;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i=0; i<5; i++)
|
||||
demo();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user