Global, local variables, storage categories for data

Source: Internet
Author: User

"Local Variables" (local variable)

1, defined in a function, the scope is only within the scope of this function.

2, defined in a compound statement, the scope is only in the compound statement.

"Global Variables" (Globals variable)

#定义在函数之外, the scope begins with the definition of the variable to the end of the source file.

"Local variable with the same name"

#不同作用域的同名局部变量, do not interfere with each other, in memory is in different storage space.

"Local variable has the same name as global variable"

#当局部变量与全局变量重名时, global variables are masked due to the local precedence principle .

"Disadvantages of global variables" ———— "high cohesion, low coupling"

Global variables can reduce the readability of the program.

The space utilization efficiency of global variables is reduced,

Global variables can reduce the generality of the program,

#####################################################

Storage categories for data

"Automatic variable" (auto variable)

#auto是局部变量的默认存储类别,

The variable automatically allocates space, and automatically frees the memory space after the program finishes executing.

"Register variable" (register variable)

"External variables" (extern variable)

"Static variables" (static variable) ·

#静态变量 can only be initialized once

"Use scenario" when you need to use the value of the last called function, you can use the static type variable.

Global, local variables, storage categories for data

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.