Skip to content
Home » C Program Without Main() Function

C Program Without Main() Function

Learn about C Program Without Main() Function in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Our program’s entry point is represented by the symbol _start. That is, the address of that symbol is the address to which the program jumps when it starts. Normally, the function _start is given by a file called crt0.o, which contains the C runtime environment’s startup code. It initializes certain variables, populates the argument array argv, counts the number of arguments, and then runs main. The exit function is invoked after the main function returns.

C Program Without Main() Function

//Compile this program with gcc -nonstartfiles
#include<stdlib.h>
void _start()
{
  int fun=my_main();
  exit(fun);
}
int my_main()
{
  puts("Program without main function.\n");
  return 0;
}

Output:

Program without main function.

compile it using: "gcc -o main main.c -nostartfiles "
and then ".\main"
it gives warnings but executes and prints output

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program Without Main() Function using Macro and Token-pasting Operator (##)
C Program Without Main() Function using Token-pasting Operator (##)