I am getting an overflow for using this. int x[471][640]; Someone told me to use Malloc? I have no idea what that is. Its not in my book nor my lectures. Any fix to this?
Asked
Active
Viewed 68 times
-6
-
Search for it. You're trying to allocate ~1.1MB on the stack (which is too much). Dynamic allocation is a very basic C concept, it will be covered by any tutorial. – Ed S. Oct 04 '14 at 19:11
-
1Type "malloc tutorial" into Google and take it from there. – NPE Oct 04 '14 at 19:12
-
here you go http://www.manpagez.com/man/3/malloc/ – Haris Oct 04 '14 at 19:13
-
2I recently [wrote a response](http://stackoverflow.com/questions/26077874/segmentation-fault-in-scanf/26077933#26077933) to another Stackoverflow question regarding large arrays (on the stack) and options to deal with them. Although the questions are different I believe the end result is from the same problem. – Michael Petch Oct 04 '14 at 19:30
1 Answers
0
If you do not know yet about C function malloc then you can try another approach. For example declare your local array as
static int x[471][640];
that is as having static storage duration.
If you also do not know yet about the keyword static then the only approach I can suggest is to declare the array globally that is outside any function. for example before main:)

Vlad from Moscow
- 301,070
- 26
- 186
- 335