【Oracle在线笔试题】const_cast的应用
来源:互联网 发布:淘宝二手官方下载 编辑:程序博客网 时间:2024/06/06 01:57
//const_cast转换符是用来移除变量的const或volatile限定符
#include <iostream>using namespace std;void func(const int &a){int b = const_cast<int &>(a);b++;cout << b <<endl;}int main(){int m=6;func(m);cout << m <<endl;return 0;}
结果输出:
7
6
因为在func中定义的b是个独立的变量,b和a是两个不同的内存单元。对b的变换,并不影响a。
变换一下,把func中的b改成引用
#include <iostream>using namespace std;void func(const int &a){int &b = const_cast<int &>(a);b++;cout << b <<endl;}int main(){int m=6;func(m);cout << m <<endl;return 0;}
输出:
7
7
因为b是a引用,所以a和b指向同一个内存单元。
#include <iostream>using namespace std;int main(){const int m=6;int &b = const_cast<int &>(m);b++;cout << b <<endl;cout << m <<endl;return 0;}
输出:
7
6
#include <iostream>using namespace std;int main(){const int &m=6;int &b = const_cast<int &>(m);b++;cout << b <<endl;cout << m <<endl;return 0;}
输出:
7
7
- 【Oracle在线笔试题】const_cast的应用
- const_cast的应用
- const_cast的应用
- const_cast的应用
- const_cast的应用
- 笔试题10. 在线笔试
- 【Oracle在线笔试题】类相关 指针 函数指针
- 亚马逊2013的一道在线笔试题
- 刷在线笔试题的网站
- 在线笔试的诀窍
- 京东软发的在线笔试
- const_cast应用
- ms在线笔试题
- 2015360在线笔试题
- indeed 在线笔试题
- 在线笔试题
- 乐事在线笔试题
- 乐事在线笔试题.
- 硬链接和软链接(hard link&soft link)
- Poj 1042 Gone Fishing
- Toast 和Timer与 Can't create handler inside thread that has not called Looper.prepare()问题
- id software编程规范
- 如何将shp数据导入Oracle Spatial
- 【Oracle在线笔试题】const_cast的应用
- android聊天表情开发
- LoadRunner--信与不信之间
- Android对Linux内核的增强:Low Memory Killer(低内存管理)
- 挑战编程 程序设计竞赛训练手册-1.6.6 解释器(Interpreter)
- 常见的棋牌游戏网站支付接口
- linux (centos)目录
- 通过spring发送email
- bean标签库---Struts标签库