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
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!