64,648
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int fun(void){
static int count = 10;//①事实上此赋值语句从来没有执行过???不是仅初始化一次吗?
return count--;
}
int count = 1;//②为什么全局count与static类型count不冲突?
int main(void)
{
printf("global\t\tlocal static\n");
for(; count <= 10; ++count)
printf("%d\t\t%d\n", count, fun());
return 0;
}
#include <stdio.h>
#include <iostream>
using namespace std;
class TestClass
{
public:
TestClass() { cout << "constructor !" << endl; }
};
int fun(void){
static TestClass tc;
static int count = 10;
//①事实上此赋值语句从来没有执行过???不是仅初始化一次吗?
return count--;
}
int count = 1; // ②为什么全局count与static类型count不冲突?
int main(void)
{
printf("global\t\tlocal static\n");
for(; count <= 10; ++count)
printf("%d\t\t%d\n", count, fun());
return 0;
}
global local static
constructor !
1 10
2 9
3 8
4 7
5 6
6 5
7 4
8 3
9 2
10 1