Home  >  Article  >  Operation and Maintenance  >  Does linux have a main function?

Does linux have a main function?

WBOY
WBOYOriginal
2022-07-21 16:24:092513browse

There is a main function in Linux; the prototype of the main function in Linux is "int main(int argc,char *argv[]){return 0;}". The C language stipulates that the parameters of the main function can only be Two, one is argc and one is argv. Since the main function cannot be called by other functions, it is impossible to obtain the actual value inside the program.

Does linux have a main function?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Does Linux have a main function?

The main function is familiar to everyone. In Linux driver debugging, we often need to write simple Linux application layer code to test the driver.

The definition of main function in linux is as follows:

int main(int argc,char *argv[]);

The prototype of main function in linux

int main(int argc,char *argv[])
{
return 0;
}

C language stipulates that the main function can only have two parameters, one is argc, one is argv and argc can only be an integer, and the second one must be an array of pointers to strings

Since the main function cannot be called by other functions, it is impossible to obtain the actual value inside the program. So, where do you assign the actual parameter values ​​to the formal parameters of the main

function? In fact, the parameter values ​​of the main function are obtained from the operating system command line. When we want to run an executable file,

type the file name at the DOS prompt, and then enter the actual parameters to transfer these actual parameters to the formal parameters of main. The general form of the command line in the DOS prompt is:

C:>executable file name parameters parameters...; However, special attention should be paid to the two formal parameters of main and the parameters in the command line. There is no one-to-one correspondence in position.

argc: The parameter indicates the number of parameters in the command line (note that the text name itself is also a parameter). The value of

rgc is determined by the parameter when entering the command line.

argv is automatically assigned by the system based on the actual number of parameters: The parameter is an array of string pointers, and the value of each element is the first address of each string in the command line (parameters are processed as strings). The length of the pointer array

is the number of parameters. The initial value of the array element is automatically assigned by the system

Extended knowledge

Usage steps

The code is as follows (example):

Does linux have a main function?

The running results are as follows

Does linux have a main function?

Recommended learning: Linux video tutorial

The above is the detailed content of Does linux have a main function?. 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