Search code examples
c++functionparameterized

C++ output shown without returning the values


compiler used-: code blocks

without returning the "c" how is variable "d" getting its value?

#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;
}

Solution

  • Write this code:

    #include<iostream>
    using namespace std;
    
    int add(int x,int y)
    {
        return x+y;//CHANGE THIS
    }
    
    int main()
    {
         int a,b;
        cin>>a>>b;
        int d=add(a,b);
        cout<<d;
    }