当前位置:网站首页>Constants and constant pointers
Constants and constant pointers
2022-07-19 05:30:00 【Learn to put down ta】
Constant
General constant number , character , character string
When used const After modifying variables, you can change variables into constants
const double pi = 3.14;
pi = 3.1415926;// If you want to change the value pi, May be an error
pointer to const
It can be seen from the above that : use const A decorated pointer is a pointer to a constant , Its value cannot be modified by dereference .
const int a = 520;
const int *p = &a;
*p = 123;// Will report a mistake
But the pointer can be modified at this time p The direction of . By contrast , Yes
Constant pointer
The pointer cannot be changed , If it points to a variable, its value can be changed , If it is a constant, it cannot be changed .
int a = 123;
int b = 520;
int * const p = &a;
*p = 111;// After action a The value of is changed to 111
p = &b;// Will report a mistake , Because the pointer is fixed
Constant pointer to constant and pointer to constant pointer
const int num = 111;
const int * const p = #// Constant pointer to constant
const int * const *pp = &p;// Pointer to constant pointer to constant
边栏推荐
猜你喜欢
随机推荐
sql时间对比
基于PaddleOCR解决文本检测训练模型与inference模型预测效果不一致的问题
Data visualization
Is the software testing training of lemon class reliable? This successful case of counter attack from the training class tells you
从20s优化到500ms,我用了这三招
Shell脚本配置root免密登录到其他主机
Router loopback port experiment
指针进阶简单总结
Network command: network card information, netstat, ARP
分布式存储-fastdfs
9.数据仓库搭建之DIM层搭建
C语言的指针函数
gradle
Easypoi之excel模板导出
MySQL transactions
Redis source code analysis - data structure and Implementation (Dictionary dict)
Online software testing training institutions lemon class and itest AI platform achieves strategic cooperation
MySQL学习笔记(4)——(基本CRUD)操作数据库中的表的数据
H5 page uses JS to generate QR code
redis 源码分析3 间断遍历的实现