- 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; // definitionIt 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