C Exercise 43
100 Classic C Language Examples
**Problem:** Learn another use of static.
**Analysis:** None.
Program source code:
Example
// Created by www.runoob.com on 15/11/9.
// Copyright (c) 2015 Runoob Tutorial. All rights reserved.
//
#include
<
stdio.h
int
main
(
)
{
int
i
,
num;
num
=
2
;
for
(
i
=
0
;
i
<
3
;
i
++
)
{
printf
(
"
num variable is %d
\
n
"
,
num
)
;
num
++;
{
static
int
num
=
1
;
printf
(
"
Built-in module num variable is %d
\
n
"
,
num
)
;
num
++;
}
}
return
0
;
}
The output of the above example is:
num 变量为 2
内置模块 num 变量为 1
num 变量为 3
内置模块 num 变量为 2
num 变量为 4
内置模块 num 变量为 3