C Language: Global variables and local variables

Source: Internet
Author: User

Local variables:

Concept: defining function Internal variables

Definition Format: Variable type variable name;

Scope: Starts from the definition of the line to the end of the block of code

Life cycle: From code execution to what line of definition begins, until the end of the code where it resides

Feature: You cannot have a variable of the same name in the same code block

Different code blocks can have variables with the same name, and internal variables override externally defined variables

Global variables:

Concept: Defining variables outside the function

Definition: Variable type variable name = value;

Declaration: Variable type variable name;

Features: 1, can not be repeated definition, but can be repeated declaration

2, the local variable can be the same name as the global variable, within the scope of the local variable, then the local variable will overwrite the global variable

3, if there is no definition of only declarations, the system automatically defines it and initializes it to 0

Scope: Starts from the defined line until the end of the file

Life cycle: Starts from the start of the program until the program exits

C Language: Global variables and local variables

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.