c++ - 显示 C++ 输出而不返回值
问题描述
使用的编译器-:代码块
在不返回“c”的情况下,变量“d”如何获得它的值?
#include<iostream>
using namespace std;
int add(int x,int y) {
int c;
c=x+y;
}
int main() {
int a,b;
cin>>a>>b;
int d=add(a,b);
cout<<d;
}
解决方案
不能在 Visual C++ 中编译,但在使用onlinedgb时确实会给出结果。
JaMiT 上面的评论链接到带有解释的正确答案。
推荐阅读
- node.js - WARNING: NODE_ENV value of 'dev ' did not match any deployment config file names(Windows)
- python - 如何在每个值的末尾删除 \n?
- android - Is it possible to change MaterialButton's style "on fly"?
- sql - 表的大小会影响 SQL Server 中插入查询的性能吗?
- css - 改进(使用 flexbox)旧的(使用浮动的邮件)网格布局,在某些浏览器中不起作用:不尊重排水沟
- batch-file - 在 .bat 文件中传递文件名变量
- xcode - 如何从 ForEach 列表中的项目访问值
- c++ - 如何使用 C++ 在 OBS 中获取/设置垂直滚动过滤器属性?
- node.js - IE 11 和 FireFox 没有对 URL 中的查询字符串进行编码,但 chrome 可以
- angular - 我的 node_modules 文件夹是灰色的,我该如何纠正?