In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to achieve local and global variables in C language", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this "how to achieve local and global variables in C language" article.
C language variable
Define the situation in 3 of the variables
Defined at the beginning of the function.
Defined in a compound statement within a function.
Defined outside the function.
C language local variable
Variables defined within a function are valid only within the scope of this function, that is, they can only be referenced within this function, and these variables cannot be used outside this function.
Variables defined within a compound statement are valid only within the scope of the compound statement and can only be referenced within this compound statement. These comparisons cannot be used outside compound statements, and these are called "local variables".
Variables defined in the main function are also valid only in the main function, not in the entire file or program because they are defined in the main function.
Variables of the same name can be used in different functions. They represent different objects and do not interfere with each other.
Formal parameters are also local variables.
Within a function, variables can be defined in compound statements, which are valid only in this compound statement, also known as "subroutines" or "program blocks".
C language global variable
Variables defined within a function are local variables, while variables defined outside the function are called external variables, and external variables are global variables.
Global variables can be shared by other functions in this file.
The valid range of global variables is from the location where the variable is defined to the end of the source file.
The function of setting global variables is to increase the channel of data connection between functions.
In order to make it easier to distinguish between global and local variables, it is a habit among C programmers to capitalize the first letter of a global variable (unspecified).
Cases of global variables and local variables in C language
# include
Int num1=10; / / defines and initializes global variables
Int main ()
{
Int num2=20;// defines local variables
Printf ("% d\ n", num1); / / output the value of the global variable
Printf ("% d\ n", num2); / / output the value of the local variable
Return 0
}
Compile and run the result:
ten
twenty
-
Process exited after 0.06448 seconds with return value 0
Please press any key to continue. . . The above is the content of this article on "how to implement local and global variables in C language". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.