C 实战练习题目41 -static定义静态变量

题目:学习static定义静态变量的用法。

程序分析:无。

实例:

 1 #include<stdio.h>
 2 int main()
 3 {
 4     void fun();
 5     for(int i=0;i<3;i++)
 6         fun();
 7     return 0;
 8 }
 9 void fun()
10 {
11     int i=0;
12     static int static_i=0;
13     printf("i=%d
",i);
14     printf("static_i=%d
",static_i);
15     i++;
16     static_i++;
17 }

以上实例输出结果为:

i=0
static_i=0
i=0
static_i=1
i=0
static_i=2

感谢你的阅读,请用心感悟!希望可以帮到爱学习的你!!分享也是一种快乐!!!请接力。。。

点击查看原文,谢谢!

原文地址:https://www.cnblogs.com/kangyifan/p/13062690.html