How the main function in C receives command line parameters

Source: Internet
Author: User

How the main (INT argc, char ** argv) function in C receives command line parameters

If the name of the main program is run.exe or run. Out, the command line will input parameters in the following way:
./Run 1 2 3 A B C

The value of argc in the main function is 7, that is, argc = 7.
The value of argv [0] is run, that is, argv [0] = "run"
The value of argv [1] is 1, that is, argv [1] = "1"
The value of argv [2] is 2, that is, argv [2] = "2"
The value of argv [3] is 3, that is, argv [3] = "3"
The value of argv [4] is a, that is, argv [4] = ""
The value of argv [5] is B, that is, argv [5] = "B"
The value of argv [6] is C, that is, argv [6] = "C"

You can use parameters as configuration items for program startup to enhance the configurability of startup parameters.

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.