Comparison of pointers and references

/ * 
time: April 17, 2020 21:36:40 
where: gfdx 
function: comparison between reference and pointer * / 
#include <iostream> 
using namespace std; 
int main () 
{ 
	int i = 5; // normal Type variable 
	int * num = & i; // Pointer to integer pointer 
	int & p = i; // Reference to integer data 
	cout << "Pointer: i is" << * num << endl; 
	cout << "Reference: i is "<< p << endl; 
	return 0; 
}

  The purpose of using a reference: you can use the indirect reference operator * without writing, so the reference simplifies the application

Guess you like

Origin www.cnblogs.com/qq1480040000/p/12722753.html