How can there be so many scopes in C language?

Source: Internet
Author: User

How can there be so many scopes in C language?
What is the scope first? As the name implies, the scope is the scope that something can work. Of course, this interpretation is too general. In C, the scope refers to declaring a variable, the region to which this variable can be accessed is its scope. The accessed area of this variable is determined by the scope of the variable identifier. The identifier scope is the area in the program where the identifier can be used. The C language compiler can be divided into four scopes: File Scope, function scope, code block scope, and prototype scope. Code block scope: a statement in a pair of braces is a code block. variables that can be used in a pair of braces have the characteristics of code scope. A local variable is a variable with a code block scope. It can only be used within the braces that declare it, and can only be used for its own code block. Other code blocks cannot use it. File Scope: variables outside the code block used have the characteristics of this file scope. From the declaration to the end of the source file, it can be accessed. A typical example is a global variable. It is usually declared before the main function and exists throughout the source file execution process until the source file ends, but other source files cannot be accessed. Prototype scope: the prototype scope is only applicable to parameter names declared in the function prototype. parameter names can be omitted in the function prototype. However, if a parameter name appears, it can be randomly named, the prototype scope prevents the parameter names from conflicting with the names of other parts of the program. Function scope: the function scope applies only to statement labels, while the statement labels apply to goto statements. The rule is that the statement labels used in a function must be unique. (Not commonly used)

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.