const
来源:互联网 发布:linux 代理客户端软件 编辑:程序博客网 时间:2024/06/05 16:56
reference : C++ Primer Plus
const*在const右边,意味着指向的数据不能修改。*在const左边,意味着指针是一个常量,地址不可以改变,但地址对应的数据可以改变。const int num = 5;int a[num] = {1,2,3,4,5};//c++中这样是可以的,但在c中不可以。void main(){ //num就是常量,就像是一个符号,不能被改变,但内存&num是可以改变的。 const int num = 10; int *p = (int *)# *p = 5; cout << num << endl;//输出10 cout << *p << endl;//输出5 cin.get();}常量不读内存,常量数组读内存#include "iostream"using namespace std;void change(const int *p){ int *pp = (int *)p; //去掉const属性 *pp = 111;}void main(){ int rat = 10; const int a = 20; const int b[5] = { 1, 2, 3, 4, 5 }; change(&rat); cout << rat << endl; //output 111 //常量不读内存 change(&a); cout << a << endl; //output 20 //常量数组会读内存 change(&b[4]); cout << b[4] << endl; //output 111 cin.get();}
0 0
- const
- const
- const
- CONST
- const
- const
- const
- const
- const
- const
- Const
- const
- const
- const
- CONST
- const
- const
- const
- pragma exception_init使用
- POJ题目1719 Shooting Contest(二分图)
- glib库线程池代码分析
- 看数据结构写代码(66) 败者树
- Go语言目录压缩,"archive/zip","path/filepath"
- const
- 如何在Mac OS X上安装和使用Visual Studio Code和ASP.NET 5
- RedHat下安装JDK的笔记
- Dither
- Android面试宝典----1.选择填空分析及答案
- 字符串各种转换
- java生成xml
- Eclipse 中设置JVM 内存
- C# WebRequest