C command line arguments

When the program is executed, values ​​can be passed to the C program from the command line. These values ​​are called command-line arguments , and they are important to the program, especially when you want to control the program from the outside, rather than hard-coding these values ​​within the code.

Command line arguments are handled using main() function arguments, where argc  is the number of arguments passed in, and argv[]  is an array of pointers to each argument passed to the program.

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

It should be noted that argv[0]  stores the name of the program, argv[1]  is a pointer to the first command line argument, and *argv[n] is the last parameter.
If no arguments are supplied, argc will be 1, otherwise, if an argument is passed, argc  will be set to 2.
Multiple command line parameters are separated by spaces, but if the parameters themselves have spaces, the parameters should be placed inside double quotes "" or single quotes '' when passing parameters.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325259031&siteId=291194637