4 つの異なる値を出力したい C の関数があるため、関数で使用するのではなく、関数の値をコードreturn
に戻す関数の引数として 4 つの異なる変数を使用することにしました。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;
}