it s about recursive functions in c

-1
#include<stdio.h>
#include<conio.h>
#include<time.h>

long int A(int m, int n);

main() {
    int x;
    clock_t t1, t2, t;
    t1 = clock();
    x = A(2, 5);
    printf("the value of x is %d\n", x);
    t2 = clock();
    t = (t2 - t1) / CLOCKS_PER_SEC;
    printf("decoding time =%d\n", t);
    return 0;
}

int A(int m, int n) {
    if (n == 0) {
        return 1;
    }
    else if(m == 0) {
        return 2*n;
    }
    else  {
        return A(m - 1, A(m, n - 1));
    }
}

Why is this code producing runtime errors like Unhandled exception at 0x002F16C9 in Console Application75.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x01202FA8)?

c
asked on Stack Overflow Oct 21, 2016 by Reddy Kowshikk • edited Oct 21, 2016 by r3mainer

1 Answer

0

On Windows you can increase the stack size by linking with e.g. /stack:4000000 to get a stack size of 4000000 bytes.

In Visual Studio proceed like this:

  • Project-Properties
  • Under Configuration Properties->Linker->System put e.g 4000000 under Stack Reserve Size

enter image description here

answered on Stack Overflow Oct 21, 2016 by Jabberwocky

User contributions licensed under CC BY-SA 3.0