Array initialisation - page 3

 
MetaNt:


This reminds me a matrices...

for the orders array, you said 0=buy and 1=sell

so how would I initialise this?

OrdersArray[10,2] = {.......}{...} ?

I think it is exactly like matrices

You initialize it with one set of braces and as many values as you can fit in the array or just one value for the whole array and then add the actual values later.

Yes I said buy and sell is 0 and 1 because when you work with orders, the ordertypes are those integer values.

Most times you will find the easiest way is to initialize the whole array to a single value (just because you have to initialize it) then add the values later.

ordersarray[10,2] = {0};

When you use for loops with arrays it all will make sense.

 
SDC:

I think it is exactly like matrices

You initialize it with one set of braces and as many values as you can fit in the array or just one value for the whole array and then add the actual values later.

Yes I said buy and sell is 0 and 1 because when you work with orders, the ordertypes are those integer values.

Most times you will find the easiest way is to initialize the whole array to a single value (just because you have to initialize it) then add the values later.

ordersarray[10,2] = {0};

When you use for loops with arrays it all will make sense.


I've noticed something

Myarray [3][4] is multi-dimensional but look

Myarray [3][4] = {x,y,z}

It is defined using a one-dimensional form, meaning that for one of the dimensions only one value is valid even though the size allows for 4, so that Myarray [2,0]=z but Myarray[2,1] = 0 and Myarray[0,2] also = z.

 
SDC:

I think it is exactly like matrices

You initialize it with one set of braces and as many values as you can fit in the array or just one value for the whole array and then add the actual values later.

Yes I said buy and sell is 0 and 1 because when you work with orders, the ordertypes are those integer values.

Most times you will find the easiest way is to initialize the whole array to a single value (just because you have to initialize it) then add the values later.

ordersarray[10,2] = {0};

When you use for loops with arrays it all will make sense.


I've noticed something

Myarray [3][4] is multi-dimensional but look

Myarray [3][4] = {x,y,z}

It is defined using a one-dimensional form, meaning that for one of the dimensions only one value is valid even though the size allows for 4, so that Myarray [2,0]=z but Myarray[2,1] = 0 and Myarray[0,2] also = z.

 
SDC:

"In the initialized sequence one or several constants can be omitted. In such a case corresponding array elements of numeric type are initialized by zero, elements of arrays of string type are initialized by string value "" (quotation marks without a space), i.e by an empty line (shouldn't be confused with a space)."

and then shows this example,

string Mas_s[4] = {"a","b", ,"d"};           // String array

it was probably meant to be:

string Mas_s[4] = {"a","b","","d"};           // String array

Yes, in the first example Mas_s[2] will be initialised with 0

      string A[4] = {"a","b", ,"d"};
      string letters = "Array A =";           
      for(int x = 0;x<4;x++)
      letters +=A[x];
      Print(letters);
      
      string B[4] = {"a","b","" ,"d"};
      letters = "Array B =";           
      for(x = 0;x<4;x++)
      letters +=B[x];
      Print(letters);
      
      string C[4] = {"a","b"," " ,"d"};
      letters = "Array C =";           
      for(x = 0;x<4;x++)
      letters +=C[x];
      Print(letters);

Result


13:03:01 aaa CADJPY,H1: Array A =ab0d

13:03:01 aaa CADJPY,H1: Array B =abd

13:03:01 aaa CADJPY,H1: Array C =ab d

 
MetaNt:


I've noticed something

Myarray [3][4] is multi-dimensional but look

Myarray [3][4] = {x,y,z}

It is defined using a one-dimensional form, meaning that for one of the dimensions only one value is valid even though the size allows for 4, so that Myarray [2,0]=z but Myarray[2,1] = 0 and Myarray[0,2] also = z.

yes if you fill array that way it fills it sequentially starting with the first dimension
 
SDC:
yes if you fill array that way it fills it sequentially starting with the first dimension


so int myarray[2][2] = {1,2} would fill

myarray[0,0]=1

myarray[1,0]=2

myarray[0,0]=1

myarray[0,1]=2

how would you get it to do this using a loop

Would you use variables i and j with limits in accordance with the array size?

 

so it should fill it in this sequence

[0,0]

[0,1]

[0,2]

[0,3]

then

[1,0]

[1,1]

[1,2]

[1,3]

then

[2,0]

[2,1]

[2,2]

[2,3]

 
MetaNt:


so int myarray[2][2] = {1,2} would fill

myarray[0,0]=1

myarray[1,0]=2

myarray[0,0]=1

myarray[0,1]=2

how would you get it to do this using a loop

Would you use variables i and j with limits in accordance with the array size?

yes you can substitute the dimensional constants with a variable

for(int i=0; i<2, i++)

{myarray[i,0] = ? // would add values to the 1st

}

 

you could also do it the other way

for(i=0; i<2; i++)

{myarray[0,i] = ?

}

 
SDC:

you could also do it the other way

for(i=0; i<2; i++)

{myarray[0,i] = ?

}


Thanks for clearing that up, it does feel a lot like matrices.