# Thread: Array size in C

1. ## Array size in C

I'm trying to declare a 2-dimensional array in C of length 40000.

int matrix[40000][40000];

but the compiler is telling me that the size of variable 'matrix' is too large. I'm using gcc and have a couple of hundred Megs of RAM on my PC.

Anyone got any ideas?

Thanx,

ROb.

2. > int matrix[40000][40000];
40000 * 40000 * 4 = 6.4GB
No where near enough RAM (or address space for that matter)

Time for plan B

3. Yeah, as Salem said (but didn't expand), you have declared to have 40000 * 40000 amount. What you want to do is:

int matrix[200][200];

Try this and tell me your result.

--Garfield

4. Tried that Garfield, thing is though i've got a data file in the form of

1 2 768
1 3 398
1 4 398.67

and there is 47306 lines like this because its the value of 218 cities distance from each other so 218*217 lines of info. I'm wondering how if anyway i can represent this in the program so that the program can retrieve the distance between cities x and y whenever it wants.

Rob.

5. > and there is 47306 lines like this because its the value of 218 cities
So that's going to be
double distances[218][218];

> 1 2 768
> 1 3 398
> 1 4 398.67
First pair are 'from' and 'to' right?

So logically you have
distances[from][to] = 768;