How to use static global static variables in C language
This article mainly introduces how to use static global static variables in c language, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
1. The static global variable is initialized only once.
2. In a single .h or .c file, ordinary global variables are the same as static-decorated global static variables.
3. The variables modified by static are stored in the static data area, and all bytes in memory default to 0x00.
Example
# include int globalNum = 100 value_static; / global variable int gAddr_for_static = 0 value_static; ram / used to save the static variable address in the function void test_static_temp () {value_static; = 10 value_static; / local static variable printf ("value_static;\ n\ n", & global); modify any global variable through the pointer! Static variable! void SetGlobalValue (int address,int v) {int * pt; pt= address; * pt= v;} int main (void) {test_static_temp (); / / address of static variable obtained from output int addr = & globalNum; printf ("initialize global variable globelNum=%d, memory address =% x\ n\ n", globalNum,&globalNum); SetGlobalValue (addr,1234) Printf ("globelNum=%d after function call, memory address =% x\ n\ n", globalNum,&globalNum); addr = gAddr_for_static;// each compiler gets a different SetGlobalValue (addr,4567); test_static_temp (); return 0 } Thank you for reading this article carefully. I hope the article "how to use static global static variables in c language" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!