Note: It is not original. It is what we hear in the classroom and prevents forgetting. So remember it!
The architecture of C language is divided into two parts: Data and functions. Of course, these two parts will eventually enter the computer's memory.
After the function is compiled, the code can be programmed and stored in the code area. The data can be divided into local and global, auto and static. Simply put, the data can be stored in the static data area, heap, and stack.
Global variables and static variables are created before the main function.
The C language requires that no executable code exists in the global zone and the executable code must enter the function. However, the functions in C language are global, so that functions cannot be nested: nested definitions make the functions defined inside the function a local function. Therefore, to solve the issue of executing each function, you can only use the nested call of the function. In this case, a function must be first executed to call a series of other functions to complete the functions of the program. The first function called is the main function.
The above is the inevitability of the existence of the main function. I am not good at writing, but I can't explain it clearly.
However, the above system encountered conflicts in C ++. The global objects of C ++ are pushed from the architecture of C prior to the execution of the main function. The global object must be created before the main function is executed, and the constructor must be executed before the main function is executed. When debugging with the following code, the result shows that the constructor is executed earlier than the main function.
# Include <iostream>
Class t
{
Public: T () {cout <"constructor" <Endl ;}
}
T;
Int main (void)
{
Cout <"Main" <Endl;
Return 0;
}
This conflicts with the C language architecture. Therefore, C ++ is not a pure object-oriented programming language. As for how to solve this system conflict, it is determined by the compiler. It may also be the first to enter the main function, but then jump to the constructor to create class objects and then return to the Code for executing the main function.