当前位置:网站首页>The usage and difference of * and & in C language and the meaning of keywords static and volatile
The usage and difference of * and & in C language and the meaning of keywords static and volatile
2022-04-23 02:15:00 【childboi】
Catalog
C In language * And & The usage and difference of
keyword static and volatile Meaning and function of
C In language * And & The usage and difference of
c Define a (int a) Variables are ambiguous , In essence, it is to allocate a address space , There is a value in it .
To avoid ambiguity ,c Specifies the a Is the value ,&a Is the address space .
Pointer to an address .
here *a Represents the value stored in the address pointed to ,a It's the address that points to .
void tes(int *i){
*i=2;
}
int main(int argc, char *argv[]){
int a=4;
int* s = &a;
tes(s);
printf("%d\n",*s);
printf("%d\n",s);
}
The above code changes the incoming value through the incoming address , Output *s by 2,s For address .
keyword static and volatile Meaning and function of
static:
c In language static Keywords have two functions , First, file scope , The second is function scope .
File scope keyword static The role of is , With static Declared global variables 、 Functions must not be referenced by other files ;
static Another use is static variables inside functions , It will only be initialized once , And variables are stored in global data segments instead of function stacks , So its lifetime will last until the program exits .
Take the chestnut of callback function : although counting() The function calls itself back several times , But static integer variables count Not initialized every time , Instead, it is initialized only once , The purpose of counting is achieved .
volatile:
volatile English means changeable . stay C In language , One definition is volatile Variable means that this variable is likely to be changed unexpectedly , Therefore, we need to be careful . in other words , When the optimizer uses this variable, it must re
Read the value of this variable from virtual memory , Instead of using a backup stored in a register .
版权声明
本文为[childboi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230209449666.html
边栏推荐
- [Dahua cloud native] micro service chapter - service mode of five-star hotels
- Realize linear regression with tensorflow (including problems and solutions in the process)
- Some tips for using proxy IP.
- 010_StringRedisTemplate
- Redis memory recycling strategy
- Shardingsphere broadcast table and binding table
- VMware virtual machine installation openwrt as side route single arm route img image to vmdk
- JSP page nesting
- Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
- Log4j2 configuration
猜你喜欢

Usage of vector common interface

Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy

Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools

Latin goat (20204-2022) - daily question 1

006_ redis_ Jedis quick start

ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage

简洁开源的一款导航网站源码

手写内存池以及原理代码分析【C语言】

【Chrome扩展程序】content_script的跨域问题

Heap overflow of kernel PWN basic tutorial
随机推荐
[chrome extender] content_ Cross domain problem of script
小程序 读取文件
[nk]牛客月赛48 D
World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]
Explain JS prototype and prototype chain in detail
New book recommendation - IPv6 technology and application (Ruijie version)
Time. In ANSI standard library H header file
【Chrome扩展程序】content_script的跨域问题
JSP page nesting
校园转转二手市场源码
IAR嵌入式開發STM32f103c8t6之點亮LED燈
中金财富跟中金公司是一家公司吗,安全吗
89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
简洁开源的一款导航网站源码
Micro build low code zero foundation introductory course
007_Redis_Jedis连接池
[leetcode daily question] 396 Rotation function
How to configure iptables to realize local port forwarding