c language

Discussion in 'Programmer's Corner' started by prejval2006, Sep 26, 2010.

  1. prejval2006

    Thread Starter Member

    Oct 25, 2006
    A process running the following code has 1KB memory allocated for the stack region.
    int iFactorial (int iNum)
    if (iNum==0)
    return (1);
    return (n*iFactorial(n-1));
    The function is called iFactorial(257). Assuming that an integer takes 4 bytes on your machine and operating system,
    find the number of times recursion will happen before a "stack overflow" occurs.

    a) 256
    b) 257
    c) 1024
    d) None of the above
  2. someonesdad

    Senior Member

    Jul 7, 2009
    Ask yourself what information is put on the stack with each function call and the question will answer itself.

    If you're not sure, then compile some code and teach yourself to read the assembly code that is output to see how the stack gets manipulated during function calls.