Take a look at the following simple reference code:
#include<iostream>
using namespace std;
int main(){
int x=12;
int &a=x;//在此&仅仅表示的是标识作用
//**声明引用的时候,必须同时对其初始化操作。
a=a+1;
cout<<a<<endl;
}
Note:
the reference itself does not take up storage space, it is just an alias for the variable name.
A reference to an array cannot be created.
Pointers are accessed by addresses, while references are accessed by aliases.
int *p=&x;
References can be used as parameters. This is a large part of the role of references! ! !
The meaning of references
1) References exist as aliases for other variables, so they can replace pointers in some occasions
2) References are more readable and practical than pointers