在C语言中,static关键字可以用来表示两种不同的含义:
void foo() {
static int counter = 0;
counter++;
printf("%d\n", counter);
}
int main() {
foo(); // 输出1
foo(); // 输出2
return 0;
}
// file1.c
static int global_var = 10;
// file2.c
extern int global_var; // 这里会报错,因为global_var的作用域被限制在file1.c内
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言中static关键字的作用是什么