可能重复:
如何修改按值传递的原始变量的内容?
我正在构建一个非常简单的程序来计算矩形的面积。然而,很简单,您会注意到我似乎无法获得返回值。我一直看到 0。可能有一个明显的答案,或者可能有一些我不明白的东西。这是我的代码:
#include<stdio.h>
//prototypes
int FindArea(int , int , int);
main()
{
//Area of a Rectangle
int rBase,rHeight,rArea = 0;
//get base
printf("\n\n\tThis program will calculate the Area of a rectangle.");
printf("\n\n\tFirst, enter a value of the base of a rectangle:");
scanf(" %d" , &rBase);
//refresh and get height
system("cls");
printf("\n\n\tNow please enter the height of the same rectangle:");
scanf(" %d" , &rHeight);
//refresh and show output
system("cls");
FindArea (rArea , rBase , rHeight);
printf("\n\n\tThe area of this rectangle is %d" , rArea);
getch();
}//end main
int FindArea (rArea , rBase , rHeight)
{
rArea = (rBase * rHeight);
return (rArea);
}//end FindArea