1.基本数据类型的引用。
#include <iostream>
using namespace std;
int main(){
int a = 3;
int &b = a;
b = 10;
cout<<a<<endl;
system("pause");
return 0;
}
2.结构体类型的引用
#include <iostream>
using namespace std;
typedef struct Coor
{
int x;
int y;
};
int main(){
Coor c1;
Coor &c2 = c1;
c2.x = 10;
c2.y = 20;
cout<<c1.x<<" "<<c1.y<<endl;
system("pause");
return 0;
}
3.指针类型的引用
类型 *&指针引用名 = 指针;
#include <iostream>
using namespace std;
int main(){
int a = 10;
int *p = &a;
int *&q = p;
*q= 20;
cout<<a<<endl;
system("pause");
return 0;
}