# Useing a single dimension array as a multi simension one

This is a discussion on Useing a single dimension array as a multi simension one within the C++ Programming forums, part of the General Programming Boards category; Ive been told that the computer can seek a number in a single dimension array faster than it can in ...

1. ## Useing a single dimension array as a multi simension one

Ive been told that the computer can seek a number in a single dimension array faster than it can in say a 4d one, I cant seem to figure out how to index to the right number in the 1d one though?

2. You might be getting thrown off by the fact that an array is zero based...
therefore to access it by row and col or any other discard the 0 element and make the array greater by 1...
see this sample

Code:
```int rows = 10;
int cols   = 10;
int *myArray;

myArray = new int[rows * cols + 1];

0 -ignored
1-10
11-20
21-30
......
91-100```
myArray[3 * 10l] = 30;
will assign the value 30 to the 31st item or item index 30...
in a two dimensional array this would be item[2][9]....3rd row 10th column....

or to loop through the items..
the following code assigns each index a value equal to it's index
starting at 1 and ending at n
Code:
```for(i=0;i<rows;i++)
{
for(j=1;j<=cols;j++)
{
myArray[i*10 + j] = ((i *10) + j);
}
}```