当前位置:网站首页>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
边栏推荐
- 001_redis设置存活时间
- 从0开始开发一个chrome插件(2)
- 89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
- What are the test steps of dynamic proxy IP?
- Shardingsphere introduction and sub table usage
- PTA: praise the crazy devil
- tp6阿里云短信 window 报 cURL error 60: SSL certificate problem: unable to get local issuer certificate
- openstack 服务的启动
- Realize linear regression with tensorflow (including problems and solutions in the process)
- JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)
猜你喜欢

011_RedisTemplate操作Hash

Arduino esp8266 network upgrade OTA

Dynamic batch processing and static batch processing of unity

有哪些常见的代理ip问题?
![[assembly language] understand](/img/73/2483bca93714e378ff5eef18bddcd1.jpg)
[assembly language] understand "stack" from the lowest point of view

What businesses use physical servers?

Leetcode39 combined sum

What is BGP server and what are its advantages?

Network jitter tool clumsy

leetcode:27. 移除元素【count remove小操作】
随机推荐
小程序 读取文件
Leetcode39 combined sum
How many steps are there from open source enthusiasts to Apache directors?
easyswoole环境配置
一加一为什么等于二
Develop a chrome plug-in from 0 (2)
Analyze the advantages and disadvantages of tunnel proxy IP.
89 logistic回歸用戶畫像用戶響應度預測
What are the common proxy IP problems?
Thinkphp内核开发盲盒商城源码v2.0 对接易支付/阿里云短信/七牛云存储
App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]
002_ Redis_ Common operation commands of string type
Consider defining a bean of type 'com netflix. discovery. AbstractDiscoveryClientOptionalArgs‘
使用代理IP是需要注意什么?
[leetcode daily question] 396 Rotation function
Kubernetes cluster installation based on Kirin SP10 server version
有哪些业务会用到物理服务器?
Want to experience homekit smart home? Why don't you take a look at this smart ecosystem
What should I pay attention to when using proxy IP?
Introduction to micro build low code zero Foundation (lesson 2)