Need help with functions, i need functions to return more than 1 value

 

Hi, i need help once more,  i never worked with functions before, but when the code starts to increase you have to use them, or you get spaghetti code,  i need help to get more than 1 returned value from each function, it's possible to do it? I've been searching, you can use something like passing by reference, so you can set a variable from the main code, and it will be passed to a selected function, but i'm getting an error in the code:


int a; 

int start()       
  {

b (a);          // i call the function and a should replace c in this function, and then get a=50, but on metatrader this indicator value is a=0 so i don't understand it

Comment (a);

return(0);
};  

void b (int c)
{
c=50;

}

I get comment value at 0, but shouldn't  it be 50? How can i make this work. Thanks for any help

 
void b (int c){   c=50;   }
Pass c by reference. Perhaps you should read the manual.
          MQL4 Reference -> Language Basics -> Functions -> Passing Parameters - Functions - Language Basics - MQL4 Reference
 
whroeder1:
Pass c by reference. Perhaps you should read the manual.
          Passing Parameters - Functions - Language Basics - MQL4 Reference
can you show me the code to make a=50? In the examples you showed me the functions only return 1 value, you can see the examples don't use void in functions examples, but i need each function to return several values, do you know a way to do it?
 
Mrluck07:
can you show me the code to make a=50? In the examples you showed me the functions only return 1 value, but i need each function to return several values, do you know a way to do it?
void b (int& c)
{
c=50;

}
PS: a function (any function) can not return several values. Pass multiple parameters by reference and that way you can have multiple values set (changed) by the function - almost the same as if it returned several values
 
Mladen Rakic:

Now it worked  exactly as i needed

Thanks a lot for the tip

 
Mrluck07:
Now it worked  exactly as i needed, so what the & about? Thanks a lot for the tip
That is the "by reference" (here is one more general (non-mql) example and an explanation what does it mean) : https://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value
What's the difference between passing by reference vs. passing by value?
What's the difference between passing by reference vs. passing by value?
  • stackoverflow.com
a parameter passed by reference a parameter passed by value? Could you give me some examples, please?
 
Mladen Rakic:
That is the "by reference" (here is one more general (non-mql) example and an explanation what does it mean) : https://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value
Great, now i understand it more, this & thing wasn't on mql4 book, have a nice day sir
Reason: