c++ const int 和int 有什么区别,const的作用是什么。【by徐玉丽】
来源:互联网 发布:苹果内存清理软件 编辑:程序博客网 时间:2024/05/01 06:11
加上const肯定有别与不加的,不然也不会出现这个定义。const int类型一旦定义以后就不能修改,int类型是随时可以修改的在取指针方面,const有略复杂的东西,但是常规的、合理的操作不应该涉及到,因为const int是用来保存一些全局常量的,这些常量在编译期可以改,在运行期不能改,听起来这像宏,其实这确实就是用来取代宏的:#define PI 3.14const float Pi = 3.14;如果你的代码里用到了100次PI(宏),你的代码中会保存100个3.14这个常数,鉴于使用常数进行运算的机器代码很多时候会比使用变量来的长,如果你换用100次Pi(const float),程序编译后的机器码里就不需要出现100次常量3.14,只要在需要的时候引用存有3.14的常量就行了,特别在复杂的运算里,3.14这个常量(其实是无法修改的变量)会被一直装载在寄存器里带来一些性能提升。清楚了const的用法,const int和int的区别就很简单,int i里的i可以被更改,是真正的变量,const int i的i不可以被更改,是有着变量外衣的常数。
0 0
- c++ const int 和int 有什么区别,const的作用是什么。【by徐玉丽】
- const int* 和 int const*的区别?
- const int*和int const*的区别
- Const int *, int const *, 和int * const 的区别:
- int *const 和 int const*的区别 (指针 和 const)
- const int *x 和 int * const x, const int& x和 int const &x的区别
- const int &x和int const &x有何区别
- C/C++_ const int * 与 int *const的区别
- const int & 和 int 的区别
- const int 和INT const区别
- const int& x和 int const &x真的有区别嗎?
- const int *p 和 int* const p 的区别详解
- int const * pci和int * const cpi的区别
- const int * pt和int * const pt的区别
- int const * p1和 const int * p1的区别
- C++ const int* p 和 int * const p的区别
- 关于const int*, int const*以及int *const的区别
- const int * 与int const * 与int * const的区别
- xpath使用
- 设计模式之-组合模式
- phpstorm 创建php文件的默认注释
- iOS - 关于dispatch_sync(dispatch_get_main_queue(), ^{...;}); 死锁问题的解释
- grunt\angularjs
- c++ const int 和int 有什么区别,const的作用是什么。【by徐玉丽】
- 按钮按下与松开的状态(颜色,形状等形态变化)
- java加解密之RSA使用
- iOS10 ATS / 非HTTPS被禁问题
- SELinux简介
- 图的深度遍历
- 机器新建用户检查
- Hive排序 cluster by column = distribute by column + sort by column
- 给Unity开发者的C#内存管理(第一部分) C# Memory Management for Unity Developers (part 1 of 3)