C: inputs to a function left unaltered by the function -


i have function in c want output 4 different values, rather using return in function decided have 4 different variables arguments function carry values out of function main code. figured if defined variables in main , fed them other function, have whatever value function gave them after exiting function. not happen though. variables end having value of 0 or close 0 (like, around 10^-310).

do have declare variables in different way/with different scope allow them keep values had in function after exiting function? or there way return multiple values in function?

here's excerpt of relative code:

void peakshift_fwhm_finder(double fwhml,double fwhmr,double peak, double max) {   ...//stuff happens these variables }  int main() {   double fwhml,fwhmr,peak,max;    ...//other stuff other variables    peakshift_fwhm_finder(fwhml,fwhmr,peak,max)   //these 4 variables have right values inside function   //but once leave function not keep values.    ...//code continues...   return 0; } 

what looking called passing reference

to achieve that, need change declaration take pointers variables. example

void foo(int * x) {     (*x)++; } 

then, can invoke function passing values through address.

int main() {     int = 10;     foo(&i);     printf("%d", i); } 

what passes address location of variable modified , function directly modifies variable @ address.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -