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 forinside the loop can survive out of the forloop does not exist, so the compiler error
Here Insert Picture Description
The following code also ibid.
Here Insert Picture DescriptionThe following are normal
Here Insert Picture DescriptionLocal 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.
Here Insert Picture Description

Published 39 original articles · won praise 4 · Views 660

Guess you like

Origin blog.csdn.net/weixin_44718794/article/details/103949558