#include <stdio.h>
void f (void)
{
static int count = 0; // static variable
int i = 0; // automatic variable
printf("%d %d\n", i++, count++);
}
int main(void)
{
for (int ndx=0; ndx<10; ++ndx)
f();
}
Run Code Online (Sandbox Code Playgroud)
例如,在这段代码中,count存储在哪里?通常,static变量将存储在数据段中,局部变量存储在堆栈中。