当前位置:网站首页>【分清楚常量指针与指针常量 Const int *与Int * Const的含义与用法】
【分清楚常量指针与指针常量 Const int *与Int * Const的含义与用法】
2022-07-23 05:43:00 【余生】
想要弄清楚这个事情,首先关键要明白:
const 属于修饰符 ,关键是看const 修饰的位置在那里
1.常量指针
所谓的常量指针,就是常量修饰符Const在最前面:如Const int *a
这里const 修饰的是int,而int定义的是一个整值
因此a 所指向的对象 值 不能通过 a 来修改,但是 可以重新给 a 来赋值,使其指向不同的对象
eg:
const int *a ;
const int b = 1;
int c = 1;
a = &b //ok 额外:注意不能通过a 来修改 b值
a = &c //ok 额外:虽然c本身不是一个常量
*a = 2 //error 为题就在这里,不能修改通过 a 所指向的对象值,最后赋值得对象是c**,因此不能通过a 来修改c值。
2.指针常量
所谓的指针常量,就是指针在最前面 如:Int * const a
这里const修饰的是 a ,a代表的是一个指针地址
因此不能赋给a其他的地址值,但可以修改a指向的值
这有点和cont int *a相反的意味,例子就不说了
eg:
Int * const a ;
const int b = 1;
int c = 1;
a = &b //OK 第一次定义,指针可以指向任意变量
a = &c //error a指针已经指向b变量,所以不能在指向其他
*a = 2 //OK 这个的意思是 通过指针a来修改b变量的值,所以b变量从之前的1 变成 2
边栏推荐
- 论文解读:《BERT4Bitter:一种基于transformer(BERT)双向编码器表示用于改善苦肽预测的基础模型》
- 谈谈转动惯量
- Using pycaret: low code, automated machine learning framework to solve regression problems
- google or-tools的复杂排班程序深度解读
- Data analysis (I)
- Nt68661 screen parameter upgrade-rk3128-start up and upgrade screen parameters yourself
- 硬件知识2--协议类(基于百问网硬件操作大全视频教程)
- All kinds of ice! Use paddegan of the propeller to realize makeup migration
- How can knowledge map, map data platform and map technology help the rapid development of retail industry
- Interpretation of the paper: using attention mechanism to improve the identification of N6 methyladenine sites in DNA
猜你喜欢

Interpretation of the paper: attention based multi label neural network for comprehensive prediction and interpretation of 12 widely existing RNA modifications

论文解读:《一种利用二核苷酸One-hot编码器识别水稻基因组中N6甲基腺嘌呤位点的卷积神经网络》

高分子物理考研概念及要点、考点总结

How to develop the liquid cooled GPU server in the data center under the "east to West calculation"?

论文解读:《提高N7-甲基鸟苷(m7G)位点预测性能的迭代特征表示方法》

利用google or-tools 求解数独难题

Use steps of Charles' packet capturing

利用google or-tools 求解逻辑难题:斑马问题

Using pycaret: low code, automated machine learning framework to solve classification problems

《数据中心白皮书 2022》“东数西算”下数据中心高性能计算的六大趋势八大技术
随机推荐
Solve Sudoku puzzles with Google or tools
Data analysis of time series (I): main components
单片机学习笔记4--GPIO(基于百问网STM32F103系列教程)
预处理指令#define,你真的懂了吗?
高电压技术考题附答案
Interpretation of the paper: a convolutional neural network for identifying N6 methyladenine sites in rice genome using dinucleotide one hot encoder
UE4 solves the problem that the WebBrowser cannot play H.264
NLP自然语言处理-机器学习和自然语言处理介绍(一)
Notes | Baidu flying plasma AI talent Creation Camp: detailed explanation of deep learning model training and key parameter tuning
Build "green computing" and interpret "Intelligent Computing Center"
液冷数据中心如何构建,蓝海大脑液冷技术保驾护航
使用PyOD来进行异常值检测
Development and deployment of steel defect detection using paddlex yolov3 of propeller
硬件知识1--原理图和接口类型(基于百问网硬件操作大全视频教程)
A hundred schools of thought contend at the 2021 trusted privacy computing Summit Forum and data security industry summit
编码器的一点理解
In depth interpretation of Google or tools' complex scheduling program
K-nucleotide frequencies (KNF) or k-mer frequencies
“東數西算”下數據中心的液冷GPU服務器如何發展?
论文解读:《利用注意力机制提高DNA的N6-甲基腺嘌呤位点的鉴定》