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
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++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++ Custom Control控件向父窗体发送对应的消息