c++的两数相加代码(利用引用来编程)
#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 <<
#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; ”。

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)