Search code examples
javac++cexecution

Execution at main method


Hii ,

We generally see that the program execution begins in the main method for the languages like C , C++ , Java (i am familiar with these). I want to know how the compiler knows the presence of MAIN method in the program .

What does the main method signify besides that it is the entry point for program execution ...How does these criteria differ for C , C++ ...

Provide any links which you think are helpful ...


Solution

  • Generally, the code that is executed at the beginning of every C or C++ program (included usually by default by compilers/linkers) does some initialization and then calls a function called main. If this function is not present, it will lead to an unresolved name when linking a program (in which all the names have to be resolved). If it is present, it will be called by the program initialization code.

    The initialization code does some housekeeping (for example, converts the return value of the main function to the exit code of the program, etc.)