c language

Thread Starter

prejval2006

Joined Oct 25, 2006
21
A process running the following code has 1KB memory allocated for the stack region.
int iFactorial (int iNum)
{
if (iNum==0)
return (1);
else
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
 

someonesdad

Joined Jul 7, 2009
1,583
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.
 
Top