# Other Languages > C and C++ >  How do I address C variables that use an typedef array in an array?

## Ben321

For example, if I have a type like this "typedef int TwoInts[2];" and then I have an array of this type like this "TwoInts MyVar[10]", how do I address the individual elements of that array?
Do I do MyVar[y][x], where y is an entry in the MyVar array (the entry being of type TwoInts), and then x selects which one of the 2 int fields within this array entry? Or would y select the int field, while x would select the entry in the array?

----------


## 2kaud

Do you mean something like:



```
#include <stdio.h>

typedef int TwoInts[2];

int main() {
	TwoInts MyVar[10] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };

	printf("%i %i\n", MyVar[1][0], MyVar[1][1]);
	printf("%i %i\n", MyVar[3][0], MyVar[3][1]);
}
```

which displays:



```
3 4
7 8
```

[3] selects the element in MyVar and then [0] or [1] selects the element of that as per TwoInts.

----------


## Zvoni

> For example, if I have a type like this "typedef int TwoInts[2];" and then I have an array of this type like this "TwoInts MyVar[10]", how do I address the individual elements of that array?
> Do I do MyVar[y][x], where y is an entry in the MyVar array (the entry being of type TwoInts), and then x selects which one of the 2 int fields within this array entry? Or would y select the int field, while x would select the entry in the array?


Speaking in VB6 this would be:
Dim Myvar(0 To 9, 0 To 1) As Long
So y would be first dimension, x the second

----------


## wqweto

In VB6 dimensions are reversed i.e. y have to be the second one in order to keep the memory layout like in C/C++

----------


## Zvoni

> 5586748[/URL]]In VB6 dimensions are reversed i.e. y have to be the second one in order to keep the memory layout like in C/C++


Damn! Thats one of those 50:50 things i can never remember.

----------


## 2kaud

Given the C++ code above, then effectively you have:



```
TwoInts temp = MyVar[3];
int myInt = temp[1];
```

c/c++ has arrays of 1 dimension. Although you can have an array of type array of type array.... which allows multi-dimensions to be used. The types of each 'array' can be different.

----------


## wqweto

> Damn! Thats one of those 50:50 things i can never remember.


In VB6 it's the natural x,y while in C/C++ you have to be able to get a pointer to y-th row with MyVar[y] so it's reversed to MyVar[y][x]

You can check which dimension is which in VB's layout like this



```
    Dim Myvar(0 To 9, 0 To 1) As Long
    Debug.Print VarPtr(Myvar(1, 0)) - VarPtr(Myvar(0, 0))
    '--> 4
    Debug.Print VarPtr(Myvar(0, 1)) - VarPtr(Myvar(0, 0))
    '--> 40
```

Obviously the second dimension "offsets" by 40 bytes so it must be "by row"

cheers,
</wqw>

----------

