You all are just *so cute*.

The _reason_ you have a main() is because when the compiler builds the program and puts the jump tables in, it has to have somewhere to jump to, to get _your code_ going.

All programs start at relative location 0x00000000 to wherever the RAM heap is loaded for their memory segment.

Why? Because zero is the only location the processor knows about-- it's always there.

So let's say your program is double-clicked on, or told to execute in some like manner. The O/S allocates a block of RAM (the "heap") for your program. It loads it into the heapspace and jumps to location zero.

At location zero, the header stub begins to execute. It quickly calculates where your globals are, where your function addresses are (the address of main offset from relative "zero") and stuffs these into the jump table so they don't have to be calculated again. When the jump tables are built, the stackframe is initialized, and a jump is made to main() (now that it knows where it is).

Literally, "main()" is a label. Just like the name of every other function in your program. Even assembly requires the use of labels. Although assembly merely starts executing at the first byte of your program, because there is no jump-table setup in assembly-- such things are resolved by the linker at assemble time.

So let's say your program gets loaded at location 0x0007FE41A, in RAM.

That is your relative "zero".

So when your code gets loaded, the O/S jumps to 0x0007FE41A. Your jumptable and init code starts to run and when its complete it jumps to the main() label to get *your* code going. If that happens to be 754 (or 0x2F2 in hex) bytes into the code segment "from relative zero" then all references to main() become:

0x0007FE41A + 0x000002F2 = address of first byte of main() function's code.

---

Now, depending on what code snippet you're writing, it may not be called "main()" at all. But there normally is some label you start with.