What will happen when the below code snippet is executed? [code] void my_recursive_function() { my_recursive_function(); } int main() {

Nguyễn Pháp

New member
What will happen when the below code snippet is executed?
Code:
void my_recursive_function()
{
   my_recursive_function();
}
int main()
{
   my_recursive_function();
   return 0;
}
A. The code will be executed successfully and no output will be generated
B. The code will be executed successfully and random output will be generated
C. The code will show a compile time error
D. The code will run for some time and stop when the stack overflows
 
Answer: D
Explanation: Every function call is stored in the stack memory. In this case, there is no terminating condition(base case). So, my_recursive_function() will be called continuously till the stack overflows and there is no more space to store the function calls. At this point of time, the program will stop abruptly.
 

Tìm kiếm

Back
Top