C Basic Knowledge "scope rules"

Source: Internet
Author: User

C Scope Rules
1. In any programming, a scope is a region of a variable defined in a program that cannot be accessed beyond that region variable. There are three places in C that can declare a variable:
A local variable inside a function or block
Global variables outside of all functions
In the function parameter definition of the formal parameter
2. Local Variables
A variable declared inside a function or block is called a local variable. They can only be used by the function or by statements inside the code block. Local variables are not known outside of the function.
3. Global variables
A global variable is defined outside a function, usually at the top of a program. Global variables are valid throughout the program life cycle and can be accessed within any function.
Global variables can be accessed by any function. In other words, global variables are available throughout the program after the declaration.
4. Formal parameters
function parameters, formal parameters, are treated as local variables within the function, and they override global variables preferentially.
5. Initializing local variables and global variables
When a local variable is defined, the system does not initialize it, and you must initialize it yourself. When you define a global variable, the system automatically initializes it.

C Basic Knowledge "scope rules"

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.