Return more than one variable from a function?

 

Want to know if this is possible (yes, I did a search already)?


int MyFun(a, b, c)

{

int x = a + b;

int y = b + c;

return(x, y);

}


int e, f = MyFun(g, h, i);


Thanks for any help!

 

void myfunc(int &a, int &b)
{
a++;
b++;
}

int start()
{
int a=0,b=0;
Alert("a: "+a+", b: "+b);
myfunc(a,b);
Alert("a: "+a+", b: "+b);
return(0);
}

Jon

 

I tested it and that is really, really cool. Are there any docs about the "&" and what it does to the variable?


Thanks!

 
Thank you for the link!
 

A more general form of what Archael wrote:

void myfunc(int &y, int &z)
{
   y++;
   z++;
}


int start()


{
   int a=0,b=0;
   Alert("a: "+ a +", b: "+b);
   myfunc(a,b);
   Alert("a: "+ a +", b: "+b);
   return(0);
}

or using globals...

int a=0,b=0;

void myfunc()
{
   a++;
   b++;
}

int start()
{
  
   Alert("a: "+a+", b: "+b);
   myfunc();
   Alert("a: "+a+", b: "+b);
   return(0);
}
 

Simply put, the '&' just means that MQL will pass the address of the variable (a reference of that variable) instead of the value of the variable. This way, once inside the function you are still playing with the "variables" that were passed instead of the "values of the variables" that were passed.

.

Jon

Reason: