热门

最新

红包

立Flag

投票

同城

我的

发布
m0_59972885
假装自己在努力
2 年前
truem0_59972885

今日C掌握
static关键字
修饰局部变量时 即使局部变量没有赋初值 也会默认为0(一般情况下编译器是不会对局部变量赋初值 除非自己赋值)
例如:
void nostatic()
{
int n = 10;

printf("%d\n", n);
n++;
printf("%d\n", n);
}

void mystatic()
{
static int n = 10;

printf("%d\n", n);
n++;
printf("%d\n", n);
}

int main()
{
nostatic();
printf("--------------------\n");
mystatic();
printf("--------------------\n");
nostatic();
printf("--------------------\n");
mystatic();
}

可知打印的出来的结果是
10
11
------------------
10
11
------------------
10
11
------------------
11
12

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
每日一图
立即登录