Click to See Complete Forum and Search --> : C++ Memory Management: Why does declaring an array cause my program to crash?


Yves M
February 13th, 2003, 01:13 PM
Q: Why does declaring an array cause my program to crash?


double x[500000];


A: Because such a large piece of memory exceeds the stack size (a stack overflow). You need to allocate the memory on the heap instead:


double* x = new double[500000];

Don't forget to delete the memory (with 'delete[]') after you are finished with it to avoid memory leaks.


FAQ contributed by: [Kevin Hall (http://www.codeguru.com/forum/member.php?u=85152)]
<br><br>