Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use static global static variables in C language

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report