c - Calling main from another function -


i new c, forgive me if query basic.

i want call main() function, , make program run infinitely. code here:

#include <stdio.h>  void message();  int main() {     message();      return 0; }  void message() {     printf("this test message. \n");      main(); } 

i expect see program run infinitely. however, runs time , stops suddenly. using counter variable, printed alongside test message, found statement "this test message." printed 174608 times after error message

segmentation fault (core dumped)

and program terminates. error mean? , why program run 174608 times (why not infinitely)?

you have stack overflow infinite recursion. make infinite loop in main:

int main() {   while (1)   {     //...   } } 

Comments