引用,是C++中提出来的一种新的使用变量的方式,即,给实际变量起个别名,通过这个别名来引用实际的变量。标准C中不支持变量的引用。只不过有这种方法。
#include <stdlib.h>
#include <stdio.h>
void f(int *t)
{
(*t)++;//注意运算优先级
}
int main()
{
int t;
t=0;
f(&t);
printf("%d",t);
return 0;
}
c++引用调用
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
void f(int &t)
{
t++;
}
int main()
{
int t;
t=0;
f(t);
cout<<t;
return 0;
}