Why does declaring double x[500000] cause my program to crash?

Because such a large piece of memory exceeds the stack size (a stack overflow). You need to allocate the memory on the heap instead:
code:
double *x = new double[500000];

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

No comments:

Post a Comment