当前位置:网站首页>C语言基础篇 —— 2-2 const关键字与指针
C语言基础篇 —— 2-2 const关键字与指针
2022-07-17 09:55:00 【Bazinga bingo】
const关键字,在C语言中用来修饰变量,表示这个变量是常量。
const用来修饰指针,有4种方式:
第一种,const int *p
p本身不是const,p指向的变量是const
第二种,int const *p
p本身不是const,p指向的变量是const
第三种,int * const p
p本身是const,p指向的变量不是const
第四种,const int * const p
p本身是const,p指向的变量也是const
const修饰的变量在GCC环境下,变量是可以改变的。因为const是gcc用来检查来确保实现(const类型的变量不能改是编译错误,不是运行错误。只要骗过编译器就可以改变,运行不会报错)。GGC在分配const修饰的变量内存空间的时候,把它和普通变量放在同一个可修改的空间内。
const主要用在告诉编译器,这个被const修饰的变量是不必改变的。更多的就是当作以后信息传入函数中,告诉编译器和程序员这是没有必要改变变量的值。
边栏推荐
猜你喜欢

【论文笔记】融合多传感器数据的抓取机械臂末端定位研究

C# - this 的用法

Anycontrol demo demo demo

C语言编译过程

数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比

Uniapp warehouse management system source code
![[troubleshooting] common problems and solutions when installing MySQL in Windows system](/img/45/339bda7ecf8879999d8ff128c1d3ab.png)
[troubleshooting] common problems and solutions when installing MySQL in Windows system

LDA classifier

Zero basic C language

Microservice splitting for stand-alone projects
随机推荐
Day 5 training
ArrayList底层分析
vscode下载历史版本
TP5 wechat withdrawal merchants transfer to change (copying is available)
OpenCV模板
每日模型系列:2022.07.11
MySQL 用户管理
Exchange array elements without creating temporary variables
Daily model series: July 11, 2022
Case sharing | build a one-stop data development platform for hehe information based on linkis+dss
【CTF】pwn2_ sctf_ two thousand and sixteen
SDL图像显示
Left connection query of Android database
认真工作后,发现周围混事的真多
idea卡顿且报错:UI was frozen for xxxxx ms问题解决
最新水果FLStudio20.9低版本版升级高版本教程
代码庆端午--粽你心意
MySQL user management
第七天训练
电脑拨号上网