首页 > 解决方案 > 显示 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;
}

标签: c++functionparameterized

解决方案


不能在 Visual C++ 中编译,但在使用onlinedgb时确实会给出结果。

JaMiT 上面的评论链接到带有解释的正确答案。


推荐阅读