Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 817173b

Browse files
static variables
1 parent 91613a7 commit 817173b

File tree

1 file changed

+21
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 10 Functions/Static_variables

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
6+
void func()
7+
{
8+
static int t = 1953; // a static variable is like a global variable, it retains her value , but it can only be accessed inside the function where it was defined
9+
t++;
10+
11+
cout<<"Variable t is "<<t<<endl;
12+
}
13+
14+
int main(void)
15+
{
16+
func(); // 1954
17+
func(); // 1955
18+
func(); // 1956
19+
20+
return 0;
21+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /