#include<iostream>
using namespace std;
void add(int &c, int &d)
{
int x, y;
cout<<"please input x and y:endl";
cin>> x >> y ;
cout <<c << "+" << d << "=" << c + d << endl;
}
int main()
{
int a = 2, b = 5;
add(a, b);
return 0;
}
定义中的 & 符号在C++中是引用的意思,相当于C语言中的指针,但是引用号不占存储空间。
注意:在c++中,输入符号cin后面没有空字符,即“endl”(最后一个字母是小写L),这个地方很多人打错。在定义中,最后输出的时候,要用引用名输出,“ cout <<c << "+" << d << "=" << c + d << endl; ”。