I save the above code in a test.mqh file. After pressing F5in MetaEditor. The compiler reports two errors: 1) *- comma expected. 2) j- variable not defined.
Can someone tell me what is the problem? and how should i correct this issue? Thanks a lot for your time and consideration .
I assume * is a pointer ? mql4 doesn't use pointers.
RaptorUK: Thank you for your prompt reply. Yes, I intend to use int * j as a pointer. If mql4 doesnot use pointers, can i use address operator as a reference to return valuevalues from a function? thanks again for your prompt reply.
If you are going to let variable be changed inside the procedure then use & before the argument instead of *:
void f (int& j) { j = 100; }
RaptorUK: Thank you for your prompt reply. Yes, I intend to use int * j as a pointer. If mql4 doesnot use pointers, can i use address operator as a reference to return valuevalues from a function? thanks again for your prompt reply.
You can pass a variable by reference as wmlab has pointed out or just return the value . . .
int f (int p) { j = 100 * p; return(j); }
Wmlab's solution can change multiple external variables during a single call. So I chose it because of its flexibility.RatptorUKand Wmlab: Many thanks for your timely and effective help.
Wmlab's solution can change multiple external variables during a single call. So I chose it because of its flexibility. Many thanks for timely and effective help.
j[3]=k;
Any suggestions to make the above above code more concise are highly appreciated....
Any suggestions to make the above above code more concise are highly appreciated....
Please use the SRC button to post code.
This isn't valid for an array . . .
j = 100;
If your function were . . .
void f (int& j) { j[9] = 100; }
a valid call would be . .
int k[10]; f(k);
then the value of k[9] would be 100
Why do yo want concise code ?
Please use the SRC button to post code.
This isn't valid for an array . . .
If your function were . . .
a valid call would be . .
then the value of k[9] would be 100
Why do yo want concise code ?
the code can not be compiled correctly....is it possible to read a document so as to avoid these frequently met issues? thank you, RaptorUK.
You should find what you need from the documentation and Book
Your issue may be due to the fact that mql4 doesn't support dynamically sized arrays, when the arrayis declared either give it the size needed . . .
int k[1000]; // array declred as having 1000 elements
or resize it as needed
int k[]; ArrayResize(k, 1000); // array resized to have 1000 elements

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I save the above code in a test.mqh file. After pressing F5in MetaEditor. The compiler reports two errors: 1) *- comma expected. 2) j- variable not defined.
Can someone tell me what is the problem? and how should i correct this issue? Thanks a lot for your time and consideration .