Linux C notes in the scope of the detailed

Source: Internet
Author: User
Tags function definition function prototype

Scope:
    when a variable is declared in a part of a program, it can be accessed only in a certain area of the program. This area is determined by the scope of the identifier.
The scope of an identifier is the area in the program where the identifier can be used.
 
1. Code scope:     all statements that lie between a pair of curly braces are called a block of code. Any identifier declared at the beginning of a code block has a code block effect Domain, which means that they can be accessed by all statements in this block of code.
    when a contemporary code block is in a nested state, the scope of the identifier declared in the inner code block ends at the end of the code block. However, if the internalThe layer code block has an identifier whose name is the same as an identifier for the outer code block, and that identifier in the inner layer hides the outer identifier--the outerLayerThe identifier cannot be accessed by your name in the inner code block.     code blocks that are not nested are slightly different. Variables declared on each block of code cannot be accessed by another block of code because their scope is notHeavythe place of overlap. 2. File scope:
     any identifiers declared outside of all blocks of code have a file scope, which represents the identifiers from where they are declared until it residesat the end of the source file, you can access it. 3. Prototype scope:The prototype scope applies only to the parameter names declared in the function prototype, in the prototype (different from the definition of the function), the name of the parameter is not required . However, if you have parameter names, you can give them whatever name you want, they don't have to match the parameter names in the function definition, and you don't have toArguments that are passed when the function is actually called, and the prototype scope prevents these parameter names from conflicting with the names of the other parts of the program. In fact, the only possibleThe conflict is to use the same name more than once in the same prototype.
4. Function scope:The function scope adapts only to statement labels, and statement labels are used for goto statements. Basically, a function scope can be simplified to a rule--All statement labels in a function must be unique. In fact, we seldom use this knowledge.



From for notes (Wiz)

Linux C notes in the scope of the detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.