Possible Duplicate:
In C, how is the main() method initially called?
I want to know, who calls the main function in C.
What is actual use of the main function ( why main is special/necessary ) ?
Can I write a c program with out main function ?
The main
function is called, in practice, by the C runtime.
You can write a program without main
but it must have an entry point. Different operating systems allow you to specify different entry points for your program, but they all serve the same purpose as main
. On Windows, you can use WinMain
. On Linux you can link without the CRT and define your own _start
function (but it cannot return!)
A program without an entry point is like a car without wheels: it doesn't go anywhere.
When you ask your operating system to run a file, it loads it into memory, and jumps to it starting point (_start
,etc). At this point, there is an code, that call main
and then exit (The linker is responsible to this part). If you will write program without main
function, the linker will give you an error, since it couldn't find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With