指针和引用的对比

/*
time: 2020年4月17日21:36:40
where:gfdx
function:引用和指针的对比*/
#include<iostream>
using namespace std;
int main()
{
	int i = 5;//普通整型变量
	int *num = &i;//指向整型的指针
	int &p = i;//整型数据的引用
	cout << "指针:i is " << *num << endl;
	cout << "引用:i is " << p<< endl;
	return 0;
}

  使用引用的目的:可以不用使用书写间接引用运算符*,因而引用简化了应用程序

猜你喜欢

转载自www.cnblogs.com/qq1480040000/p/12722753.html