当前位置:网站首页>C language - growth diary-04- preliminary exploration of local variables (local variables)
C language - growth diary-04- preliminary exploration of local variables (local variables)
2022-06-11 07:43:00 【Zhangxueheng】
Today, when writing a topic of exchanging numbers , I came across such a problem

According to the definition of exchange function , All values should change , But the result is not so , In contrast, I have another program , I put the print function (printf) Put it in swap Function , Values change

It seems that the problem is printf Functions are located in different locations . Then I'll try to convert three groups of data printf Functions are also placed in swap Function instead of main Function .

It seems that the result is the same as we predicted , Different positions lead to different results . I listened to the lecture again , It is found that the reason for this is the local variable ( Also called local variables ) Why .
For example, in a code block , Declared a variable
{
int a=0;
}
Put this in the main function , for example

Through this example, we can see the local variables a2 And global variables a1、a3 Change between .
also a2 Only affected by its block , because a3 be equal to a1, So local variables a2 Only in its code block .
I will continue to study c language knowledge , Share with you !
--------------------------------------------——--————————————————————————-
2022.2.28 Continue to update :
According to the rules of the local variables found :
![]()
That is to say, in the block {} The use of functions inside has limitations , for example :

This is the definition of a local variable , It is only valid within the block , Find a block when you get out , It no longer exists
边栏推荐
- 【IoT】智能硬件:如何获取硬件产品的wifi信号强度
- 【AtCoder1998】Stamp Rally(整体二分+并查集)
- Compound RateModel合約解析
- Sdl-3 YUV playback
- 【AtCoder2306】Rearranging(拓扑)
- You got 8K in the 3-year function test, but you were actually pretending to work hard
- 【AtCoder2304】Cleaning
- 【CodeForces1019E】Raining season(边分治+斜率优化)
- MFC auxiliary CString string splicing
- 【AtCoder2387】+/- Rectangle
猜你喜欢
随机推荐
【HDU6357】Hills And Valleys(DP)
C language Yanghui triangle code
MFC debugger OutputDebugString override
Euler's theorem and its extension (with proof)
After 4 years of naked resignation from the test, the test post of 15K interview was rubbed on the ground, and the result made me collapse and cry
20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
Djikstra solves the shortest circuit with negative weight
Zero foundation self-study SQL course | union joint query
Second remaining learning notes
What is the lifecycle of automated testing?
Configuration software -- control drag and drop
20200803 T3 my friends [divide and conquer NTT optimization recursion]
Cartland number application
[IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products
Implementation of stack (C language)
2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
MFC custom string linked list
[atcoder1998] stamp Rally
Wc2020 course selection
Compound ratemodel contract analysis









