Why doesn't return modify the value of a parameter to a function

前端 未结 7 1105
盖世英雄少女心
盖世英雄少女心 2020-12-22 13:57

Possible Duplicate:
How to modify content of the original variable which is passed by value?

I am building a

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 14:21

    You need to assign the return value of FindArea to rArea. At the moment, FindArea assigns the product to its local variable of the same name.

    Alternatively, you can pass the address of main's rArea to modify that, that would look like

    FindArea(&rArea, rBase, rHeight);
    

    in main with

    void FindArea(int * rArea, int rBase, int rHeight) {
        *rArea = rBase * rHeight;
    }
    

提交回复
热议问题