static 变量 怪状
时间:2010-06-05 来源:sinodragon21
#include <stdio.h>
#include <stdlib.h>
void test()
{
static int temp = 0;
printf("temp = %d.\n", temp);
temp ++;
return;
}
int main()
{
int i = 0;
for(i=0; i<10; i++)
{
test();
}
system("PAUSE");
}
运行结果:
temp = 0.
temp = 1.
temp = 2.
temp = 3.
temp = 4.
temp = 5.
temp = 6.
temp = 7.
temp = 8.
temp = 9.
请按任意键继续. . .
#include <stdlib.h>
void test()
{
static int temp = 0;
printf("temp = %d.\n", temp);
temp ++;
return;
}
int main()
{
int i = 0;
for(i=0; i<10; i++)
{
test();
}
system("PAUSE");
}
运行结果:
temp = 0.
temp = 1.
temp = 2.
temp = 3.
temp = 4.
temp = 5.
temp = 6.
temp = 7.
temp = 8.
temp = 9.
请按任意键继续. . .
相关阅读 更多 +