当前位置:网站首页>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 .
边栏推荐
- 默认插槽,具名插槽,作用域插槽
- TeamTalk源码分析之win-client
- C语言高级用法--函数指针:回调函数;转换表
- Word frequency statistics & sorting
- [Hongke technology sharing] how to test DNS server: DNS performance and response time test
- 线性dp求解 最长子序列 —— 小题三则
- Fabric.js 自由绘制圆形
- MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
- 没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
- The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
猜你喜欢

关于Flink框架窗口(window)函数最全解析

Daily learning 2

PHP linked list creation and traversal

HMS core machine learning service helps zaful users to shop conveniently

kaggle如何使用utility script

What is erdma? Popular science cartoon illustration

The most complete analysis of Flink frame window function

Fabric. JS zoom canvas

There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '

Selenium element positioning method
随机推荐
Daily learning 2
Fabric.js 动态设置字号大小
Go operation redis
腾讯云 TStor 统一存储通过信通院首批文件存储基础能力评测
Penetrate the remote connection database through the Intranet
[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)
Uniapp automated test learning
2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
你知道Oracle的数据文件大小有上限么?
MQ教程 | Exchange(交换机)
Fabric.js 手动加粗文本iText
线性dp求解 最长子序列 —— 小题三则
数据湖(十一):Iceberg表数据组织与查询
篇9:XShell免费版安装
Development and design of animation surrounding mall sales website based on php+mysql
P1042 [NOIP2003 普及组] 乒乓球
NLA自然语言分析,让数据分析更智能
OpenHarmony笔记-----------(四)
没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028