C language Command line parameter argc,argv[] Detailed

Source: Internet
Author: User

Main (int Argc,char *argv[])

1.ARGC is an integer

2.ARGV pointer to pointer (can be understood as:char **argv or:char *argv[] Or:char argv[][], argv is an array of pointers )

Note: the main () parenthesis is a fixed notation.

3. Here is an example to understand the use of these two parameters:

Assuming that the program name is prog,

When only prog is entered, the parameters that are transmitted by the operating system are:

Argc=1, which indicates that there is only one program name.

ARGC has only one element, Argv[0] points to the program path and name of the input:./prog

When input prog para_1, there is a parameter, then the parameters transmitted by the operating system are:

Argc=2, which indicates that there is a parameter in addition to the program name.

Argv[0] points to the program path and name of the input.

ARGV[1] points to the parameter para_1 string.

When the input prog para_1 para_2 has 2 parameters, the parameters that are transmitted by the operating system are:

Argc=3, which indicates that there are 2 parameters in addition to the name of the program.

Argv[0] points to the program path and name of the input.

ARGV[1] points to the parameter para_1 string.

ARGV[2] points to the parameter para_2 string.

4.void Main (int argc, char *argv[])

Char *argv[]: argv is an array of pointers, the number of his elements is argc, which holds pointers to each parameter

Reference: http://blog.csdn.net/yukiooy/article/details/4682989 (click on the link to view detailed instructions and relevant examples)

C language Command line parameter argc,argv[] Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.