引用、指针的使用对比(注意* &符号不要用乱了)
来源:互联网 发布:sql数据优化 编辑:程序博客网 时间:2024/05/13 09:05
#include<iostream>
int main()
{
using namespace std;
int rats = 101;
int &rodents = rats;
int *pt = &rats;
cout << "rats = " << rats<<endl;
cout << "rodents =" << rodents << endl;
cout << "pt = " << *pt<<endl;
rodents++,
cout << "rats = " << rats<<endl;
cout << "rodents =" << rodents << endl;
cout << "pt = " << *pt<<endl;
cout << "rats address =" << &rats<<endl;
cout << "rodents address =" << &rodents << endl;
cout << "pt address=" << pt;
return 0;
int main()
{
using namespace std;
int rats = 101;
int &rodents = rats;
int *pt = &rats;
cout << "rats = " << rats<<endl;
cout << "rodents =" << rodents << endl;
cout << "pt = " << *pt<<endl;
rodents++,
cout << "rats = " << rats<<endl;
cout << "rodents =" << rodents << endl;
cout << "pt = " << *pt<<endl;
cout << "rats address =" << &rats<<endl;
cout << "rodents address =" << &rodents << endl;
cout << "pt address=" << pt;
return 0;
}
要注意:int *pt = &rats;包括pt=&rats; *pt=rats这两层意思。
对于int & rodents=rats;则这里的&并非是取地址符号,而是一个应用标准符号。
由结果可以知道,其实rodents其实与rats都是对于同一个地址的,同一个内容的变量名称。即李晓明同时也是胖子。
0 0
- 引用、指针的使用对比(注意* &符号不要用乱了)
- 指针和引用的对比
- 指针和引用的使用注意点-----常量指针和常量引用
- 人民币符号的使用注意
- 条款31: 千万不要返回局部对象的引用,也不要返回函数内部用new初始化的指针的引用 (转自effective c++ second edition)
- 千万不要返回局部对象的引用,也不要返回函数内部用new初始化的指针的引用
- 不要返回局部对象的引用,也不要返回函数内部用new初始化的指针的引用
- C++引用和指针的对比
- 一个存储对象的数组要注意的地方: 存储的对象不要空指针异常了
- 指针 引用 对比
- 遇到问题时不要乱了方寸
- 指针和引用对比 理解引用起到别名的作用
- 引用类型的使用注意
- 探讨PHP引用&符号的一些注意问题
- 探讨PHP引用&符号的一些注意问题
- BASE64要注意不要使用JDK的
- 模板继承中注意的一个问题,只能使用指针或引用的形式
- C++基础之引用与指针的区别与联系、常引用使用时应注意的问题
- 垃圾回收器种类
- #ifdef __cplusplus
- ASP.NET WebApi MediaTypeFormatter参数绑定的研究,支持POST文本方式的JSON字符串绑定
- windows环境编译x264最新版本
- 学习笔记----递归函数
- 引用、指针的使用对比(注意* &符号不要用乱了)
- csdn first 博客
- nefu 168 万岁影院
- iOS 自动化生成API文档
- Hybrid APP --- OC,JS 混编
- CGImageDestination Reference
- Android Studio: Error:Execution failed for task ':app:dexDebug'
- android线程控制UI更新(Handler 、post()、postDelayed()、postAtTime)
- 不使用第三个变量,进行两个变量的值交换