Computer Science, asked by nikhilsimidi, 6 months ago

How many times the below C program will print "India" ? #include<stdio h>
int main()
{
printf("India"), main();
return 0
)​

Answers

Answered by pratyush15899
11

Answer:

The ans is :

Till stack overflows.

Explanation:

stack overflow occurs when too much memory is used on the call stack.

Here function main() is called repeatedly and its return address is stored in the stack. After stack memory is full. It shows stack overflow error.

Answered by vishakasaxenasl
0

Answer:

This code will print India infinite times until memory is exhausted.

Explanation:

The given code block is:

#include<stdio h>

int main()

{

printf("India"), main();

return 0;

}

  • We can see that the main function is called inside itself that is we are calling the same function again and again. This is called recursion.
  • But this recursion is applied without any termination or base condition which means once the function starts calling itself there is no mean by which this call can be terminated.
  • This will cause infinite function calls and India will be printed infinite time.
  • Now you might think when this program will stop. Well, the program will stop when all the memory of the stack is exhausted. This is also known as stack overflow error.

#SPJ3

Similar questions