|
|
back to boardWhy Runtime error (Stack Overflow)??? #include <iostream> #include <math.h> using namespace std; void square() { long long int n; scanf("%lld", &n); if(n!=-1) { square(); printf("%.4f\n", sqrt(n)); } return; } int main() { square(); return 0; } Re: Why Runtime error (Stack Overflow)??? Posted by decay 28 Oct 2018 18:22 http://acm.timus.ru/help.aspx?topic=cpp&locale=en Visual C++ Only. In order to increase the size of a stack and to avoid its overflow when using a “deep” recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB): #pragma comment(linker, "/STACK:16777216") Re: Why Runtime error (Stack Overflow)??? sorry i don't understand .. how to set the size of the stack??? If you can explain... it might help me..... Re: Why Runtime error (Stack Overflow)??? Posted by decay 30 Oct 2018 12:41 #pragma comment(linker, "/STACK:16777216") Put the line above in the very beginning of your program, that all. Re: Why Runtime error (Stack Overflow)??? You shouldn't touch stack size at all. You shouldn't implement algorithms with linear depth of recursion, not more then logarithmic depth. You shouldn't place big arrays/objects on stack. Imagine you have 1-2K stack at all. You should get/implement stack data structure and solve problem using it. |
|
|