2.2&2.3 Variables

  • Variables defined outside any function body are initialized to zero.With one exception, which we cover in §6.1.1(p.205), variables of built-in typedefined inside a function areuninitialized. The value of an uninitialized variable ofbuilt-in type is undefined (§2.1.2, p.36). It is an error to copy or otherwise try to access the value of a variable whose value is undefined. 
  • Any declaration that includes an explicit initializer is a definition. We can provide aninitializer on a variable defined asextern, but doing so overrides theextern. An externthat has an initializer is a definition: 

extern double pi = 3.1416; //  definition

It is an error to provide an initializer on an extern inside a function. 

Variables must be defined exactly once but can be declared many times.

  • The identifiers we define in our own programs may not contain two consecutiveunderscores, nor can an identifier begin with an underscore followed immediately byan uppercase letter. In addition, identifiers defined outside a function may not beginwith an underscore. 
  • A reference is not an object. Instead, a reference is just another name for analready existing object. 
  • After a reference has been defined, all operations on that reference are actuallyoperations on the object to which the reference is bound 
  • 对于block的范围:
    {
    int tmp = 980;
    }

    cout << tmp << endl;
    会报错:

    error:use of undeclared identifier 'tmp'

  • int *p; int *&r = p; //r is a reference to the pointer p




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值