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

前端 未结 7 1068
盖世英雄少女心
盖世英雄少女心 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:37

    FindArea (rArea , rBase , rHeight);
    

    doesn't work like you think it does. In C, parameters are passed by value; that means modifying area inside the function modifies only a local copy of it. You need to assign the return value of the function to the variable:

    int FindArea(int w, int h) { return w * h; }
    
    int w, h, area;
    
    // ...
    area = findArea(w, h);
    

提交回复
热议问题