静态变量的使用

 static Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
using namespace std;
void fun_static_test(void)
{
    static int temp=0;//============================带static 存储类型修饰符
    
        cout<<temp++<<" ";
    
}
void main(void)
{
    for(int i=0;i<10;i++)
    {
        fun_static_test();
    }
}
 Nostatic Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
using namespace std;
void fun_static_test(void)
{
    int temp=0;
    
    cout<<temp++<<" ";
    
}
void main(void)
{
    for(int i=0;i<10;i++)
    {
        fun_static_test();
    }
}



猜你喜欢

转载自blog.csdn.net/damon1118/article/details/31352373
今日推荐