Home  >  Article  >  Backend Development  >  What does the execution of a C language program always start from?

What does the execution of a C language program always start from?

青灯夜游
青灯夜游Original
2020-10-26 14:11:1054931browse

The execution of a C language program always starts from the main function. In a C language source program, regardless of whether the main function is written at the front or back of the program, the execution of the program always starts from the main function and ends in the main function.

What does the execution of a C language program always start from?

Tutorial recommendation: "c language tutorial video"

C language is a high-level language, C language source After the program is compiled by the C language compiler, a suffix is ​​generated. The binary file of OBJ (called the object file) is finally converted by a software called "Link". The OBJ file is connected with various library functions provided by the C language to generate a suffix. EXE executable file. Obviously C language cannot be executed immediately.

A C program has one and only one main function. In addition to the main function, there can be several other functions. Each function implements a specific operation.

In a C language source program, regardless of whether the main function is written in the front or back of the program, the execution of the program always starts from the main function and ends in the main function.

The main function, also known as the main function, is the starting point of program execution. Main is relative, just like the overtones of phonetic theory, which are other functions in the program except main. It is a model that is generated to cater to people's way of thinking, rather than a certain one. There are primary and secondary functions, and the execution is clear and logical, which not only modularizes the program but also creates a closed whole.

Program execution always starts from the main function. If there are other functions, it will return to the main function after completing the calls to other functions. Finally, the main function ends the entire program. When the program is executed, the main function is called by the system. The main function is called after initialization of non-local objects with static storage duration is completed during program startup. It is the designated entry point for a program in a hosted environment (that is, an operating system). Entry points for stand-alone programs (boot loaders, operating system kernels, etc.) are implementation-defined.

The formal parameters in the two formal parameter forms of the main function allow arbitrary multi-byte strings to be passed from the execution environment (they are often called command line parameters), each pointer argv[1]. .argv[argc-1] points to the first character of each of these strings. argv[0] is a pointer to the first characters of a null-terminated multibyte string (or the empty string "" when the execution environment does not support it) representing the name of the program itself used to execute it. These strings can be changed, although changes to them are not propagated back to the execution environment: they can be used with std::strtok, for example. The size of the array pointed to by argv is at least argc 1, and its last element argv[argc] is guaranteed to be a null pointer.

The above is the detailed content of What does the execution of a C language program always start from?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn