当前位置:网站首页>常量与常量指针
常量与常量指针
2022-07-17 05:08:00 【学会放下ta】
常量
一般常量数字,字符,字符串
当用const修饰变量后可以把变量变为常量
const double pi = 3.14;
pi = 3.1415926;//如果你想修改值pi,则会报错
指向常量的指针
由上可知:用const修饰的指针就是指向常量的指针,不可通过解引用来修改其值。
const int a = 520;
const int *p = &a;
*p = 123;//会报错
但是此时可以修改指针p的指向。与之相反,有
常量指针
意为指针的指向不可改变,如果其指向的是变量则可改变其值,若是常量则不可改变。
int a = 123;
int b = 520;
int * const p = &a;
*p = 111;//作用后a的值被改为111
p = &b;//会报错,因为指针的指向是固定的
指向常量的常量指针和指向常量的常量指针的指针
const int num = 111;
const int * const p = #//指向常量的常量指针
const int * const *pp = &p;//指向常量的常量指针的指针
边栏推荐
猜你喜欢

Teach you to reproduce log4j2 nuclear weapon level vulnerability hand in hand

How to deal with the mismatch between subtitle files and video files

Cesium geojson数据的添加与移除

线程池如何监控,才能帮助开发者快速定位线上错误?

ambari集群扩容节点+扩容服务操作

MySQL lock

UML (use case diagram, class diagram, object diagram, package diagram)

The first smart contract program faucet sol

Online software testing training institutions lemon class and itest AI platform achieves strategic cooperation

Web3js development technology
随机推荐
网络命令:网卡信息,netstat,arp
MySQL安装配置教程(超级详细)
Excel imports long data and changes to 000 at the end
Redis source code analysis - data structure and Implementation (Dictionary dict)
聊聊redis分布式锁的8大坑
Network command: network card information, netstat, ARP
ambari 2.7.5集成安装hue 4.6
用户态协议栈-基于netmap的UDP实现
Rk356x u-boot Institute (command section) 3.4 usage of MEM memory related commands
GoFrame 错误处理的常用方法&错误码的使用
Rxjs源码解析(一)Observable
js 原生对象加属性
基于libco的协程实现6 libcurl的同步接口的实现方案
2022年春招最新消息:IT互联网行业平均薪资18500元
[first launch in the whole network] one month later, we switched from MySQL dual master to master-slave
Easypoi excel multi sheet import
MySQL installation and configuration tutorial (super detailed)
Cityengine 3D pipe modeling tutorial
mysql的缓存方案问题解决
Use of log4j