Four types of variable storage supported by C language

Source: Internet
Author: User

http://blog.csdn.net/zhandoushi1982/article/details/5425835

A) Auto:auto is called an automatic variable (local variable). A local variable is a variable (sometimes also called an automatic variable) that is described inside a function. All non-full variables are considered local variables, so auto is never actually used. Local variables are automatically generated when the function is called, but not automatically initialized, and the variable disappears automatically as the function call ends. The next time this function is called, it will be automatically generated and then assigned again, and automatically disappears when exiting.
Two) static:static is called a static variable. Depending on the type of the variable can be divided into static local variables and static global variables.

1. Static local variables: It differs from local variables in that the variable is always present when the function exits, but cannot be used by other functions; When you enter the function again, the last result is saved. Others are the same as local variables.

2. Static whole variable: A variable that is visible only in the source file in which it is defined and not in other source files. It differs from global variables in that global variables can be used by other source files and static global variables can only be used by the source file in which they reside.
III) Extern:extern is called an external declaration. To make a variable or function available in addition to the source file in which it is defined, it can also be used by other files. Therefore, each program module file is notified, which can be described by extern at this time.

For example, extern u8 Tpwakeupswitch;extern int tpwakeupswitch_read (); Be sure to add the return type, in person there is no return type, the quoted variable is a very strange value.
Four) Register:register is called a register variable. It can only be used for integer and character variables. The variable that the definition register describes is stored in the register of the CPU, and an integer register variable can be written as: Register int A;
For the storage location of the above four kinds of data: Register variable exists in the register of the CPU, the auto type variable has the memory stack, the static type local variable and global variable and the extern type variable (i.e. global variable), exists in the static area of the memory.

Four types of variable storage supported by C language

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.