Global variables and local variables---C

Source: Internet
Author: User

Local variables:

Scope: Within a function (including parameter {except for special formal parameters}) or within a code block

Definition: Inside a function, including formal parameters, within a code block

Life cycle: Allocates memory from the defined line until the end of the last line within the code block it belongs to or the end of the return

Storage location: Local variables stored in the stack that are automatically freed when the scope ends

Note: Different scopes can define the same local variable, otherwise it is not possible. Uninitialized defaults are random values (garbage values)

Global variables:

Scope: outside a function or block of code

Life cycle: Starts from the defined line until the end of the last line of the owning program

Storage location: Static Storage Area

Note: If a function has local variables named the same as the global variable, then the nearest principle

Multiple variables with the same name point to the same storage space. Uninitialized defaults to 0

Global variables and local variables---C

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.