当前位置:网站首页>常量指针和指针常量
常量指针和指针常量
2022-07-02 06:27:00 【programmercherry】
常量指针和指针常量的区别详解
* (指针)和 const (常量)谁在前就先读谁;
* 象征指针,const 象征内容;
谁在前面谁就不允许改变
1. 常量指针
int a = 10;
int b = 20;
const int* p = &a; //const在前,定义为常量指针
p = &b; //正确,指针的指向可以更改
//*p = 20; //错误,指针指向的值不可以改
特点:指针的指向(指向的地址)可以修改,但指针指向的值不可以修改
(内容不可以重新赋值,内容的改变可以通过修改地址指向后变换)
常量指针本质是指针,常量修饰它,表示这个指针是一个指向常量的指针(变量)。指针指向的对象是常量,那么这个对象不能被更改。
2.指针常量
int a = 10;
int b = 20;
int* const p = &a; //*在前,定义为指针常量
*p = 20; //正确,指针指向的值可以更改
//p = &b; //错误,指针的指向不可以改
特点:指针的指向(指向的地址)不可以修改,指针指向的值可以修改。
必须初始化,地址跟随一生。
指针常量的本质是一个常量,并且使用指针来修饰它,那么说明这个常量的值应该是一个指针
扩展:
this 指针的本质是 指针常量 指针的指向不可以修改
边栏推荐
- How to turn on night mode on laptop
- Look for we media materials from four aspects to ensure your creative inspiration
- [binocular vision] binocular correction
- C语言的库函数
- [C # note] the data in DataGridView saved in WinForm is excel and CSV
- Mmdetection model fine tuning
- CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
- 【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
- Execution of procedures
- 【Mixup】《Mixup:Beyond Empirical Risk Minimization》
猜你喜欢
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
The internal network of the server can be accessed, but the external network cannot be accessed
What if the laptop can't search the wireless network signal
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
【学习笔记】反向误差传播之数值微分
【MagNet】《Progressive Semantic Segmentation》
[multimodal] clip model
Open3d learning note 4 [surface reconstruction]
利用Transformer来进行目标检测和语义分割
Common CNN network innovations
随机推荐
【Programming】
Open3d learning note 4 [surface reconstruction]
What if the laptop task manager is gray and unavailable
Graph Pooling 简析
【MagNet】《Progressive Semantic Segmentation》
The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
【学习笔记】反向误差传播之数值微分
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
EKLAVYA -- 利用神经网络推断二进制文件中函数的参数
Network metering - transport layer
【Batch】learning notes
How do vision transformer work? [interpretation of the paper]
Open3d learning notes 1 [first glimpse, file reading]
The difference and understanding between generative model and discriminant model
Prompt 范式简述
open3d环境错误汇总
jetson nano安装tensorflow踩坑记录(scipy1.4.1)
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
C语言的库函数
最长等比子序列