您的位置:首页 > 编程语言 > C语言/C++

2.2&2.3 Variables

2015-08-03 17:29 525 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ primer 学习摘要