C-notes - variable scope and lifetime
1. Scope
What scope is 1.1?
Scope refers to what extent (simple and can be understood as brace range) can access this variable.
1.2 Scope how to use?
The following code
Compile error because i just for
inside the loop can survive out of the for
loop does not exist, so the compiler error
The following code also ibid.
The following are normal
Local variable scope within the braces variable definition.
2. survival
What survival period is 2.1?
When a variable appears to perish when.
For local variables, consistent survival and scope.
2.2 survival of how to use?
In short,Do not return the address of a local variable
3. namesake Hide
In the same scope, the same variables are being given; in a different scope, internal variables are hidden external variables.