【发布时间】:2013-08-01 16:59:52
【问题描述】:
我在 C 语言中有一个函数,我想输出四个不同的值,因此我决定将四个不同的变量作为函数的参数,而不是在函数中使用 return,这些变量会将它们的值从函数中带回我的main 代码。我想如果我在main 中定义变量并将它们提供给我的另一个函数,它们将具有函数在退出函数后赋予它们的任何值。这不会发生。变量最终的值为 0 或接近 0(例如,大约 10^-310)。
我是否必须以不同的方式/具有不同的范围声明我的变量,以允许它们在退出函数后保留它们在函数中的值?或者有没有办法在一个函数中return多个值?
以下是相关代码的摘录:
void PeakShift_FWHM_Finder(double fwhml,double fwhmr,double peak, double max)
{
...//stuff happens to these variables
}
int main()
{
double fwhml,fwhmr,peak,max;
...//other stuff to other variables
PeakShift_FWHM_Finder(fwhml,fwhmr,peak,max)
//These four variables have the right values inside the function
//but once they leave the function they do not keep those values.
...//code continues...
return 0;
}
【问题讨论】: