当前位置:网站首页>const-modified pointer variable (detailed)
const-modified pointer variable (detailed)
2022-08-10 15:21:00 【Wink to】
const修饰的指针变量
一、未被const修饰的指针变量
Pointer variables can be modified
例1:
#include <stdio.h>
int main()
{
//未被const修饰的指针变量
int a = 10;
int b = 20;
int* p = &a;
*p = 20;//可修改
p = &b;//可修改
retrun 0;
}
二、constThe decorated pointer points to the content
指针 “指向的内容” 不可修改
例2:
#include <stdio.h>
int main()
{
// const如果放在*的左边
int a = 10;
int b = 20;
const int* p = &a;//const与最近的*结合,修饰的是指针 “指向的内容(即&a的值)” ,保证(&a的值)不能通过指针(*p)来改变
*p = 100;//原本的*p=10不能被修改,所以这里的*p=100是错误的,
p = &b;//But the contents of the pointer variable itself(原本&a)可以修改
return 0;
}
三、const修饰的指针变量本身
指针 “the content of the variable itself” 不可修改
例3:
#include <stdio.h>
int main()
{
// const如果放在*的右边,
int a = 10;
int b = 20;
int* const p = &a;//const与最近的p结合,修饰的是指针变量本身(即p),保证指针 “变量的内容(&a)” 不能被修改
p = &b;//原本的p=&a不能被修改,所以这里的p=&b是错误的!
*p = 100;//但指针 “指向的内容” (即&a的值),可以修改
}
边栏推荐
猜你喜欢

SWIG tutorial "two"

Based on Azuki Series: NFT Valuation Analysis Framework "DRIC"

Redis -- Nosql

Do not access Object.prototype method ‘hasOwnProperty‘ from target object....

波士顿房价预测

Mysql statement analysis, storage engine, index optimization, etc.

Appium for APP automation testing

SWIG教程《二》

QOS function introduction

Mysql语句分析、存储引擎、索引优化等详情
随机推荐
网络安全(加密技术、数字签名、证书)
Oracle数据库备份dmp文件太大,有什么办法可以在备份的时候拆分成多个dmp吗?
WSL 提示音关闭
SWIG tutorial "two"
JS entry to proficient full version
程序员=加班??——掌握时间才能掌握人生
容器化 | 在 S3 实现定时备份
SWIG教程《四》-go语言的封装
【数仓设计】企业数仓为什么要进行分层?(六大好处)
640. 求解方程 : 简单模拟题
Meaning and names of 12 nautical miles, 24 nautical miles and 200 nautical miles
基于ArcGIS水文分析、HEC-RAS模拟技术在洪水危险性及风险评估
$'\r': command not found
数字藏品平台系统开发实战
面试面到了一个腾讯30k出来的,有见识到何为精通MySQL调优
Introduction to the Internet (2)
《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
Redis -- Nosql
易基因|深度综述:m6A RNA甲基化在大脑发育和疾病中的表观转录调控作用
物资采购小程序开发制作功能介绍