小编yuv*_*esh的帖子

为什么全局变量总是初始化为'0',而不是局部变量?

可能重复:
为什么全局变量和静态变量初始化为默认值?

看代码,

#include <stdio.h>

int a;
int main(void)
{
    int i;
    printf("%d %d\n", a, i);
}
Run Code Online (Sandbox Code Playgroud)

产量

0 8683508
Run Code Online (Sandbox Code Playgroud)

这里'a'用'0'初始化,但'i'用'垃圾值'初始化.为什么?

c variables global local

52
推荐指数
4
解决办法
7万
查看次数

"文件范围"和"程序范围"之间有什么区别

全局声明的变量被称为具有程序范围
使用static关键字全局声明的变量据说具有文件范围.

例如:

int x = 0;             // **program scope**   
static int y = 0;      // **file scope**  
static float z = 0.0;  // **file scope** 

int main()  
{  
   int i;   /* block scope */  
   /* .
      .
      .
   */ 
   return 0;  
}  
Run Code Online (Sandbox Code Playgroud)

这两者有什么区别?

c scope storage-class-specifier

21
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×2

global ×1

local ×1

scope ×1

storage-class-specifier ×1

variables ×1