C++ outline and interview questions (1): Variable

1.1. Contents

1.1.1Variable:

(1) Types: bool, char, int, long, longlong, float, double, long double.

(2) Range: 1 byte = 8 bits. - 1 bit, 7bits, 4 bytes, 4 bytes, 8 bytes, 4 bytes, 8 bytes, 8 bytes.

(3) unsigned: the unsigned version is usedfor taking the absolute value of a signed variable. It prevents the overflow.

(4) Initial value: for global/staticvariables, they are zero; for local ones, they are 0xccc (debug mode)/ a randomvalue (release mode).

(5) local/static/global: (Very important!)

(5.1)local variable: defined locally (isonly visible to certain functions, usu in a pair of curly braces); its valuestored in the stack of this function (i.e., the stack of this thread);disappear (its value will not be recovered) when the functioin ends; it hides a global variable of the same name(use scope resolution operator to distinguish them).

(5.2)global variable: defined globally(outside of any function, i.e. out of any pair of curly braces); local to thefile define them, and use extern to declare them in another file where they areused; they are initialized to be zero; they are stored in the global/staticstorage area (i.e., are visible to all threads of one process); will disappearwhen the program ends (i.e., the process terminates).

(5.3)static variable: has types ofvariables: local and global; combine the features of local and globalvariables; static local is only visible to the function where to declare themand initialized to be zero if not specific; static variable is stored in theglobal/static storage area, but they are not visible to other functions (i.e.,threads); their value will not disappear when the function ends (i.e., theirvalues will be same as that when the function ends, then they are used forrecord the system status, e.g., thetimes a function is called); static global variables are only visible tothefunctions declared in this file (i.e., cannot use extern to refer them inanother file, then from thisperspective, static and global are anonymous); static variable is used for decrease the coupling of functions anddependency on global variables (this can also simplify the design ofinterface).

(6)define/declare/refer:

(6.1)declare: set a name can be used byother variables or functions in the current file.

(6.2)define: declare and initialize avariable.

(6.3)refer: declare a variable which isdefined in some oth

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值