How to use the return value of a function with parameters inside another function

后端 未结 6 1275
孤城傲影
孤城傲影 2021-01-29 15:59

All these functions are outside the int main():

int func1(int x) {

    int v1 = 6 * x;
    return v1; // the input argument will be 2, so v1 = 12
}

int func2()         


        
6条回答
  •  感情败类
    2021-01-29 16:43

    Could you clarify your question? From my understanding you're doing what you want correctly.

    double add_5(double x) {
        return x + 5;
    }
    double nested_method(double x) {
        double myVariable = add_5(x); //my variable = x + 5
        //other code//
        return myVariable;
    }
    int main() {
    double myInput = 123;
        std::cout << nested_method(myInput) << std::endl; //output should = 128
    }
    

    If a method asks for 'n' parameters to call the method you must give it each of those 'n' parameters (of the apropriate type).

    ignoring overloads / default values etc

提交回复
热议问题