Introduction
C++ is one of the most widely used programming languages for competitive programming. Learning C++ reinforces essential computer science principles while also providing access to a wide range of professional options.
The main() function is the program's entry point in C++ programming. However, from the standpoint of program execution, it is not. Calls to a few more functions are made before the execution flow reaches main(), which establishes arguments, prepares environment variables for program execution, and so on.
Executing program with main() function
An Executable and Linkable Format (ELF) file is the executable file created after compiling C source code. Every ELF file has an ELF header with an e entry field that includes the program memory location where the executable will begin to run. The _start() function is located at this memory address. The loader checks for the e_entry field in the ELF file header after loading the application. ELF (Executable and Linkable Format) is a standard file format for executable files, object code, shared libraries, and core dumps in UNIX systems.
Example :
Consider the following program saved with the file named ninja.cpp
int main()
{
return(0);
}
Now run the following instructions to compile it.
gcc -o ninja.cpp
Now that an example executable has been produced, we may analyse it with the objdump utility.
objdump -f ninja.exe
On my PC, this outputs the following crucial information about the program. Look at the start address in the example below; this is the address that points to the _start() function.
ninja.exe: file format pei-i386
architecture: i386, flags 0x0000013a:
EXEC_P, HAS_DEBUG, HAS_SYMS, HAS_LOCALS, D_PAGED
start address 0x004012e0