# Thread: how number of two-dimensional array store ?

1. ## how number of two-dimensional array store ?

can I define as follows:
Code:
`   char a[785][106];`
for example , I define a two-dimensional array
Code:
`       char a[MAX1][MAX2];`
the MAX1 and MAX2 is how size?

2. You can do like this
Code:
```#define MAX1 785
#define MAX2 106
char a[MAX1][MAX2];```

3. Originally Posted by BEN10
You can do like this
Code:
```#define MAX1 785
#define MAX2 106
char a[MAX1][MAX2];```
Can I assign MAX1 VARIABLE equal 100000000000?
what is maxium value of MAX1 ?

4. That depends on your compiler and your hardware and operating system.

Why don't you do a little experiment and see. When the array is too big, your compiler should give you an error to let you know that.

Tell us what you can get. It will be large, but not *that* large!

5. The array will get stored in the stack, which is generally of 1-2MB, so depending on it, the memory occupied by the array should never overflow this much amount. So, you can't do what you are asking for, it'll result in stack overflow.

6. Originally Posted by BEN10
The array will get stored in the stack, which is generally of 1-2MB, so depending on it, the memory occupied by the array should never overflow this much amount. So, you can't do what you are asking for, it'll result in stack overflow.
It'll be stored on the stack only if it is defined inside of a function.
If it's outside of any function then it'll be stored in the data segment.

7. Originally Posted by zcrself
Can I assign MAX1 VARIABLE equal 100000000000?
what is maxium value of MAX1 ?
Hell no! Your computer wont have one hundred billion bytes of memory. And if your MAX2 is 106 as well then that's over ten-trillion bytes, which is probably well over your hard disk and RAM combined.

Even an array that can only just fit in memory usually isn't practical. You don't pick array bounds at random anyway. You have to consider how big it actually needs to be, or whether an array is even the right thing to use anyway. A sparse multi-way trie could be an alternative.

8. Originally Posted by itCbitC
It'll be stored on the stack only if it is defined inside of a function.
If it's outside of any function then it'll be stored in the data segment.
Can you tell me if there's any restrinction on size of data segment just like there's on stack(1-2MB)?

9. Originally Posted by BEN10
Can you tell me if there's any restrinction on size of data segment just like there's on stack(1-2MB)?
Just use malloc to make you're two dimensional array, and try to make an educated guess how much memory you need to begin with. It's probably not billions of bytes. If your guess is not enough, you can use realloc to get more at any time.