Array initialisation - page 4

 
SDC:

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]


I see, but since the initialisation is one-dimentional how can the third and second sets be valid?
 

Wait

in

int Mas_i[3][4] = { 0, 1, 2, 3,   10, 11, 12, 13,   20, 21, 22, 23 };

does 3 represent the number of sets, and 4 the number of distinct numbers within the set?

{(w,x,y,z) (a,b,c,d) (i,j,k,l)}

 

Yes that is how it is dimensioned when you fill the array using initialization, 3 sets of 4.

hmmm i know its late and am getting tired but still ..

if you were to use a loop to fill it

int myarray[3,4]={0};

for(int i=0; i<4; i++)
{
myarray[i,0] = i;
}

that would be the first set of 4 right ? But you cant do that, I would fill the array in a loop the other way around, so it would create 4 sets of 3 ... like the [10,2] array for ten tickets ... ok i got to go to bed i cant think about this anymore now lol

Edit: the initialization sequence fills the array [0,i] [1,i] [2,i] I had to think about that for a minute lol... so really I am in a bad habit of doing [10,2] I should do [2,10] arrays for ten tickets so it matches the way initialization would do it.

 
I finally get it.
 

I think there is still something about array initialisation though ... the sequence of initialization is not what I thought it was .. The [10,2] array is a correct way to handle 2 sets of ten corresponding values, for example the ten order tickets with corresponding types for each ticket.

The way we might enter them in a loop would be:

for(i=0; i<10; i++)
{
 MyArray[i,0] = ticket[i];  
 MyArray[i,1] = type[i];
}

So all ten tickets are in put in the first dimension, types in the second

then run a second loop [i,1] to enter the types

But if we were to enter them one at a time in an initialization sequence we would have to do ticket type ticket type ...

MyArray[10,2] = {ticket1, type1, ticket2, type2, ticket3, type3 etc ...

That is because the initialization sequence is:

MyArray[0,0]

MyArray[0,1]

MyArray[1,0]

MyArray[1,1]

MyArray[2,0]

MyArray[2,1]

etc ...

I think I was too tired last night to be considering that lol ...

Alternatively...

You can use the [2,10] array

this means the tickets are entered in a for loop the other way around

for(i=0; i<10; i++)
{
MyArray[0,i} = ticket[i];
MyArray[1,i] = type[i];
}
This time the initialization would be ticket ticket ticket ticket etc........ type type type type ....etc

the sequence would be

MyArray[0,0]

MyArray[0,1]

MyArray[0,2]

MyArray[0,3] etc through [0,9]

then

MyArray[1,0]

MyArray[1,1]

MyArray[1,2] etc ....

Reason: