当前位置:网站首页>C语言中*与&的用法与区别 以及关键字static和volatile 的含义
C语言中*与&的用法与区别 以及关键字static和volatile 的含义
2022-04-23 02:10:00 【childboi】
目录
C语言中*与&的用法与区别
c中定义一个(int a)变量具有二义性,本质上是分配一个地址空间,在里面存了一个值。
为了避免歧义,c规定了a是值,&a是地址空间。
指针指向一个地址。
这里*a代表指向的那个地址里存的值,a是指向的那个地址。
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);
}
上面代码通过传入地址改变传入的值,输出*s为2,s为地址。
关键字static和volatile 的含义和作用
static:
c 语言中static 关键字有两个作用,一是文件作用域,二是函数作用域。
文件作用域关键字static 的作用是,以static 申明的全局变量、函数不得被其他文件所引用;
static 另外一个用途是函数内部静态变量,只会被初始化一次,而且变量存储在全局数据段中而不是函数栈中,所以其生命期会一直持续到程序退出。
举个回调函数的栗子:虽然counting()函数多次回调自身,但是静态整型变量 count 并没有每次都被初始化,而是只初始化了一次,达到了计数目的。
volatile:
volatile英文意思是易变的。在C语言中,一个定义为volatile 的变量是说这变量很可能会被意想不到地改变,因此需要小心对待。也就是说,优化器在用到这个变量时必须每次重新
从虚拟内存中读取这个变量的值,而不是使用保存在寄存器里的备份。
版权声明
本文为[childboi]所创,转载请带上原文链接,感谢
https://blog.csdn.net/childbor/article/details/124343858
边栏推荐
- They are all intelligent in the whole house. What's the difference between aqara and homekit?
- Redis memory recycling strategy
- Some tips for using proxy IP.
- PHP & laravel & master several ways of generating token by API and some precautions (PIT)
- Micro build low code zero foundation introductory course
- PTA: Romantic reflection [binary tree reconstruction] [depth first traversal]
- Shardingsphere read write separation
- What should I pay attention to when using proxy IP?
- What problems will you encounter when dialing VPS?
- 校园转转二手市场源码
猜你喜欢
What categories do you need to know before using proxy IP?
Want to experience homekit smart home? Why don't you take a look at this smart ecosystem
Is it better to use a physical machine or a virtual machine to build a website?
89 logistic regression user portrait user response prediction
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
New book recommendation - IPv6 technology and application (Ruijie version)
006_ redis_ Sortedset type
什么是api接口?
009_Redis_RedisTemplate入门
How to set computer IP?
随机推荐
Some tips for using proxy IP.
What is a proxy IP pool and how to build it?
tp6阿里云短信 window 报 cURL error 60: SSL certificate problem: unable to get local issuer certificate
Heap overflow of kernel PWN basic tutorial
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
How does Axure set the content of the text box to the current date when the page is loaded
【Chrome扩展程序】content_script的跨域问题
Multithreading technology core
我国科学家揭示突破水稻产量瓶颈新机制
[Dahua cloud native] micro service chapter - service mode of five-star hotels
World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
Applet reads files
89 logistic回歸用戶畫像用戶響應度預測
006_redis_jedis快速入门
What businesses use physical servers?
浅析静态代理ip的三大作用。
Hyperscan -- 2 compilation
Use of push() and pop()
VMware virtual machine installation openwrt as side route single arm route img image to vmdk
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space