-7

Why does calling main() inside the body of main() cause an finite loop?

#include<stdio.h>
int main()
{
    printf("\n Sonata Software");
    main();
    return 0;
}

2 Answers2

0

This "loop" terminates or is "finite" because you keep calling main() from within main(), eventually using up all the stack frame space you have and resulting in a StackOverflow

David Xu
  • 5,555
  • 3
  • 28
  • 50
0

This program will not run. Main is not a userdefined function, that you'll call it as function within main as recursion. It'll show some error.

Indranil Mondal
  • 2,799
  • 3
  • 25
  • 40
  • The rules for C and C++ are different; C allows (or at least, doesn't explicitly forbid) calling `main` from within the program. – John Bode Jun 13 '14 at 21:56