C 存储指示器 (The storage class specifier)

在C中有四种存储指示器,下文一一介绍每种指示器的作用:

Auto指示器:

  1. Default initial value is garbage (computer generated) 默认值是随机的无意义的
  2. Scope is local to the block in which declared.作用于限于声明变量的块中

  3. Life is till control remains within the block.程序块控制其生命周期

  4. Stored in the computer's memory (RAM) 存储于内存中,其实是在栈里面

  5. Memory is economically used.块结束将自动释放内存

  6. Built is protection as they are local.只在声明块里面有效

  7. They do not retain value once control has come out from the block. Each time control is entered into the block a new variable is created and the same dies when control exits. 出了作用域就不能存取数据了

  8. They are created on stack. 变量存储在栈中

Static指示器:

  1. Default initial value is zero.默认值是0
  2. Storage is memory (in the stack).存储于栈中

  3. Internal static have no linkage. 内部静态变量无耦合(意思是独立的,和其他任何地方都无关系)

  4. External static have internal linkage.外部静态变量有耦合(意思是耦合的,在外部某个地方一定已经有定义过该变量)

  5. Life till program execution is not over. 程序不止,生命不止,当然仅仅限于当前文件有效。 也就是说即使全局静态变量也不能被其他文件访问到。

  6. Static variable are initialized only once.静态变量只会初始化一次

  7. Static variables are initialized before the execution of program begins thus they are called load time variable.静态变量是在程序执行之前完成初始化,所以叫加载时变量。

  8. They retain the value between different function calls.它会随着function里面相关的操作改变存储的值。

Register指示器:

  1. Variable are stored within CPU registers. 变量请求存储于寄存器
  2. Writing register storage class is simply a request to the compiler so variable may not be stored in CPU registers if they are not free/available.只是请求,未必最后存储寄存器

  3. You will never come to know whether variables are stored within register or within memory.没法知道它最后是否存储在寄存器还是在内存

  4. Number of registers is limited by the type of CPU.随着CUP型号的不同,内部寄存器的数量也是不同的有限的

  5. They are usually limited to the char and int type variables though some compiler permits other type also.往往只有整型和字符型变量可能被存储在寄存器,其他类型一般不支持

  6. Default initial value is garbage.默认值没有意义

  7. Scope is local to the block in which declared.只在声明块中有效

  8. Life is block only.块执行完,变量释放,该关键字不能用来声明全局变量

  9. You can not take address of a register class type variable.不能进行取地址操作

Extern指示器:

  1. Default initial value is zero.默认值是0
  2. Scope is global from the point of definition to the rest of program or we can say they have file scope.作用范围限于该文件内,不能跨文件

  3. Extern keyword is used when a variable is declared and tells the compiler about the type of identifier.常常用于表明变量的作用域

  4. The definition is outside the outermost block and it allocates memory storage.定义必须位于所有块之外

  5. The use of external variables provides a way so that information can be shared among number of functions.表明该变量可以被同一文件的函数共享

  6. The use of extern keyword is optional as external variables are recognized by the location of their definition within the program.关键字EXTERN可以随意使用,只要能该变量有在program中作为全局变量定义过

  7. An external variable declaration cannot include the assignment of initial values.声明不能给初始值

  8. Persistent storage of a variable retains the current value.该变量存储当前的值

  9. The value is globally available.该变量的值在program范围内有效

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值