当前位置:网站首页>2. Const pointer
2. Const pointer
2022-07-02 14:30:00 【Little BigUs】
const Qualifiers are used to mark a variable as read-only , But it's a little complicated when decorating pointers .
First ,const int *pa
and int const *pa
The effect is the same , These two are completely equivalent , This const Modification is *pa This whole , in other words *pa This whole is read-only , however pa( No addition *) It can be modified . The variable it points to can also be modified . for instance
int a = 100;
const int *pa = &a;
printf("%d\n",*pa);//100
a = 200;
printf("%d\n",*pa);//200
int a = 100;
int b = 200;
const int *pa = &a;
printf("%d\n",*pa);//100
pa = &b;
printf("%d\n",*pa);//200
int a = 100;
const int *pa = &a;
printf("%d\n",*pa);//100
*pa = 200;// Report errors ,*pa yes const Type , read-only
and int * const pa
in pa It's also a pointer , But this const Modification is pa Instead of *pa This whole , in other words , At this time, you can use the *pa To modify the a The value of the , however pa It's immutable , That is to say pa Can only point to a 了 , You can't point him at b, because pa The value of is the address of the target it points to , This is read-only .
Of course we can use const int * const pa
This format , In this way, it is pa and *pa All read-only .
边栏推荐
- Fabric.js 自由绘制椭圆
- <口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
- freemarker的使用
- [Hongke technology sharing] how to test DNS server: DNS performance and response time test
- Fabric. JS free draw circle
- docker mysql
- 万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
- Fabric.js 上划线、中划线(删除线)、下划线
- Delete element (with transition animation)
- A white hole formed by antineutrons produced by particle accelerators
猜你喜欢
PHP linked list creation and traversal
[Hongke technology sharing] how to test DNS server: DNS performance and response time test
Development and design of animation surrounding mall sales website based on php+mysql
php链表创建和遍历
没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
Codeforces Round #803 (Div. 2)(A~D)
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
Pycharm连接远程服务器
每日学习2
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
随机推荐
全屋Wi-Fi:一个谁也解决不好的痛点?
Design and implementation of car query system based on php+mysql
uni-app中使用computed解决了tab切换中data()值显示的异常
Yyds dry goods inventory software encryption lock function
Analysis of CPU surge in production environment service
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
PyQt5_ Qscrollarea content is saved as a picture
P1042 [noip2003 popularization group] Table Tennis
Development and design of animation surrounding mall sales website based on php+mysql
Fabric. JS manual bold text iText
NLA自然语言分析,让数据分析更智能
没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
Yolov3 & yolov5 output result description
STM32-DAC实验&高频DAC输出测试
一般来讲,如果频繁出现inconsistent tab and space的报错
快解析:轻松实现共享上网
STM32标准固件库函数名(一)
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
Quarkus学习四 - 项目开发到部署
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022