How to reuse the same array, but starting at another index in mql5?
How to reuse the same array, but starting at another index in mql5?
Loading saved threads...
hl037_ · External communityPost link
External question — Stack Overflow Stack Exchange
Author: hl037_
Original post: https://stackoverflow.com/questions/78006187
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
In C / C++, you can make an "array view" using a pointer like this :
int array[100];
int * ptr = &array[50]; // note that array + 50 would work too
printf("%d", ptr[3]);
How could you achieve the same in mql5 without copying the full array ?
(This is to pass to functions like SocketSend() )
Quote
Report
Bishow Gurung · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Bishow Gurung
Original post: https://stackoverflow.com/a/78153714
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I don't think we can create pointer in mql5. However, For Array View you can do something like this.
int myArray[5] = {1, 2, 3, 4, 5};
ArrayPrint(myArray, 0, ",", 0, 2); // 0: starting index and 2: element count
//Prints 1,2
Quote
Report
joserogerio84 · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: joserogerio84
Original post: https://stackoverflow.com/a/78211326
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
You pass the array by reference, the function SocketSend is prepared for it.
If you only want to pass a part of the array, then you must make a copy.
A example of passing by reference:
void OnStart(){
int arr[5]= {1, 2, 3, 4, 5};
PrintArrayExample(arr);
}
void PrintArrayExample(int& a[]){
for(int i=0; i < ::ArraySize(a); i++)
Print(a[i]);
}
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Bishow Gurung Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/78153714 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I don't think we can create pointer in mql5. However, For Array View you can do something like this. int myArray[5] = {1, 2, 3, 4, 5}; ArrayPrint(myArray, 0, ",", 0, 2); // 0: starting index and 2: element count //Prints 1,2
Checking account access…