当前位置:网站首页>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的值),可以修改
}
边栏推荐
- fatal error C1083 Unable to open include file 'io.h' No such file
- Systemui status bar to add a new icon
- Unfinished mathematics test paper ----- test paper generator (Qt includes source code)
- 学习MySQL 临时表
- Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
- 王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)
- 使用mysq语句操作数据库
- Parallels 将扩展桌面平台产品,以进一步改善在 Mac 上运行 Windows 的用户体验和工作效率
- Boss raises salary!Look at my WPF Loading!!!
- 兆骑科创创业赛事活动发布平台,创业赛事,项目路演
猜你喜欢
随机推荐
JS entry to proficient full version
Flask框架——MongoEngine使用MongoDB数据库
"Thesis Reading" PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
Azure IoT 合作伙伴技术赋能工作坊:IoT Dev Hack
宝塔面板开放Redis给指定外网机器
解读STEAM教育中的表现性评价
[Data warehouse design] Why should enterprise data warehouses be layered?(six benefits)
[Semantic Segmentation] DeepLab Series
Problem solving-->Online OJ (19)
奢侈品鉴定机构小程序开发制作功能介绍
强意识 压责任 安全培训筑牢生产屏障
Boss raises salary!Look at my WPF Loading!!!
Lilac Garden
王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)
WSL 提示音关闭
微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
1004(树状数组+离线操作+离散化)
线上线下课程教学培训小程序开发制作功能介绍
Based on Azuki Series: NFT Valuation Analysis Framework "DRIC"
【语义分割】DeepLab系列