[C++渐进]引用与指针

基本类型:int double float 等均属于基本类型

复合类型:基于其他类型定义的类型,目前只接触了引用和指针;

引用和指针,都实现了对其他对象的间接访问;

引用:引用即别名;

注意: 1、某个对象的引用并非对象,本质只是该对象的别名,因而不能定义引用的引用;

2、函数将引用作为形参时,相当于直接对实参进行操作;由于函数的返回值只有一个,所以通常加上一个引用形参来将我们需要的

量的值传回主函数;

3、变量前加&表示取变量的首地址,只有在定义变量时加&才表示定义引用;

4、the reference is not  an object ,so there isnot a pointer to a referrence;but there are referrences to pointers for pointers are objects;

int ival=1024;
int &refVal=ival;               //refVal是ival的别名
int &refval;                    //报错,引用必须被初始化
int *p=&ival;                   //&表示取地址,不表示引用
int func(&x,&y);                //x,y是实参的引用

指针:指向对象地址;

空指针:int *p=nullptr;means p is an empty pointer;and p can be transfered into any other type;

int *p1=nullptr;                //等价于=0,meaning p1 is a empty pointer
int *p2=0;
int *p3-NULL;                   //pre-include cstdlib;is replaced in C++ by nullptr
int *p4,p5;			//p4 is a pointer to type int;p5 is a int;the fundamental 
<span style="white-space:pre">				</span>//type is "int" not "int *",* is only a strict to p4; 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值