Array initialisation - page 2

 
MetaNt:
How does array[0,0] have a value that was declared for Myarray[3][4]?

I wrote array[0,0] when I should have wrote Myarray[0,0]; I'll edit it.

 
MetaNt:

I'm clueless right now..

Isn't Myarray[3][4] multi-dimensional, if so why can I only call values by changing the value of one of the dimensions?

You call each index individually as you need it.

just think of it as a variable that can contain multiple values. The reason for the indexing is to identify each value. Multi demensional arrays are generaly for the purpose of separateing several groups of data for example

a single dimensional array for holding ten order ticket numbers

int ordersarray[10]

ordersarray[0] =ticket1;

ordersarray[1] = ticket2; etc

but then you might want to use the same array to hold also the order types, buy or sell.

so instead you make it a two dimensional array

int ordersarray[10,2]

now it can hold ten tickets and their coresponding order types

ordersarray[0,0] = ticket .... ordersarray[0,1] = ordertype

ordersarray[0,1] = nextticket .... ordersarray[0,2] = next order type

 
SDC:

You call each index individually as you need it.

just think of it as a variable that can contain multiple values. The reason for the indexing is to identify each value. Multi demensional arrays are generaly for the purpose of separateing several groups of data for example

a single dimensional array for holding ten order ticket numbers

int ordersarray[10]

ordersarray[0] =ticket1;

ordersarray[1] = ticket2; etc

but then you might want to use the same array to hold also the order types, buy==0 sell==1

so instead you make it a two dimensional array

int ordersarray[10,2]

now it can hold ten tickets and their coresponding order types

ordersarray[0,0] = ticket .... ordersarray[0,1] = ordertype

ordersarray[0,1] = nextticket .... ordersarray[0,2] = next order type


So if I were to print ordersarray[0,0] would it give the int value for ticket1 and 0, e.g. 12340
 

yes except fix my mistake I wrote this incorrectly:

ordersarray[0,0] = ticket .... ordersarray[0,1] = ordertype

ordersarray[0,1] = nextticket .... ordersarray[0,2] = next order type

 

I was getting my indexes confused myself now lol...

Should have been:

ordersarray[0,0] = ticket1 ordersarray[0,1] =type

ordersarray[1,0] = ticket2 ordersarray[1,1] =type

ordersarray[2,0] = ticket3 ordersarray[2,1] = type

ordersarray[3,0] = ticket3 ordersarray[3,1] = type

etc

 
SDC:

yes except fix my mistake I wrote this incorrectly:

ordersarray[0,0] = ticket .... ordersarray[0,1] = ordertype

ordersarray[0,1] = nextticket .... ordersarray[0,2] = next order type


ordersarray[0,0]=ticket value0 ordersarray[0,1]=ticket value1

ordersarray[0,1]=ticket value1 (not next ticket value) ordersarray[0,2]=ticket value 0

 
SDC:

I was getting confused myself now lol...

Should have been:

ordersarray[0,0] = ticket1 ordersarray[0,1] =type

ordersarray[1,0] = ticket2 ordersarray[1,1] =type

ordersarray[2,0] = ticket3 ordersarray[2,1] = type

ordersarray[3,0] = ticket3 ordersarray[3,1] = type

etc

sorry does

Ordersarray[0,1]

not display the ticket number, only the type?

 

In the guide they use this

as a way to illustrate values being called from the array, yet when values are being indexed only one dimension is used..

 

It is probably better just to consider the indexes as conveniences but no matter what you do, you always have to use both dimensions to access the array

so in my ticket example, index all the tickets with the first dimension

0,0

1,0

2,0

3,0 ets

index all the types with the 2nd dimesion

0,1

0,2

0,3

0,4

 
SDC:

Yeah the trouble is when you try to look at it like a physical object there are several ways of doing it, do you consider the first dimension as rows or as colums.


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] = {.......}{...} ?

Reason: