关于const变量
来源:互联网 发布:迅龙数据软件注册码 编辑:程序博客网 时间:2024/06/11 21:52
说明:测试环境dev-c++
最近复习C语言,在复习const变量时发现如下特性。定义const变量a
const int a = 10;
假如 a = 11;编译报错。
但是假如使用指针来访问const变量的内存,则是可以修改a变量的。
如:
#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]){ const int a = 10; int *b; b = (int *)&a; printf("%d\n",a); printf("%d\n",*b); *b = 11; printf("%d\n",a); printf("%d\n",*b); system("PAUSE"); return 0;}
这说明const只能帮助程序员发现无意的修改,并不能保证恶意的修改。
- 关于const变量
- 关于const修饰变量
- 关于const变量的思考
- 关于const类型变量的一些知识
- 关于const变量的一点理解
- 关于const变量的一点理解
- error:关于const变量来初始化数组
- 关于 static const修饰的变量
- 关于C/C++中的const变量与const指…
- 关于C++ const:const变量,cosnt输入参数,const返回值,const成员函数
- const变量
- const变量
- const变量
- const变量
- const变量
- const 变量
- const变量
- const函数,const变量
- linux下安装后缀为bin的Java JDK
- HDU--4018(Parsing URL)
- REST是什么
- linux可执行文件bad interpreter解决方法
- Extjs TreePanel Reload()方法 ,该怎么处理
- 关于const变量
- gwt服务端怎么获得前台表单中的数据
- CTreeCtrl图标使用方法 ---两种图标切换选中与未选中
- iphone上传文件到php做的服务器的有关问题
- 约瑟夫环解法(1)
- Linux 系统进程的五种状态
- lua_call的使用
- HDU--4027(Can you answer these queries?)
- 生物信息学常用软件—2(PCR引物设计及相关软件使用)