>> so why then some programs have the int main at the end.
The actual order of the source file is irrelevant, the compiler takes care of putting things into their correct places in the executable.