Main function parameter argc, argv description

Source: Internet
Author: User

Reprinted from

Http://www.opencv.org.cn/index.php/Main%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0argc%EF%BC%8Cargv%E8%AF%B4%E6%98%8E

 

The main function in C/C ++ often carries the argc and argv parameters, as follows:

Int main (INT argc, char ** argv)

Int main (INT argc, char * argv [])

What are the functions of these two parameters? Argc refers to the number of input parameters in the command line. argv stores all command line parameters. Assume that your program is hello.exe. If you run this program on the command line
Command to enter the directory where the hello.exe file is located) run the following command:

Hello.exe Shiqi Yu

The value of argc is 3, argv [0] is "hello.exe", argv [1] is "Shiqi", and argv [2] is "yu ".

The following program demonstrates the use of argc and argv:

# Include <stdio. h>

Int main (INT argc, char ** argv)
{
Int I;
For (I = 0; I <argc; I ++)
Printf ("argument % d is % S./N", I, argv [I]);

Return 0;
}

If the false statement code is compiled into hello.exe, run

Hello.exe a B c d e

Will get

Argument 0 is hello.exe.
Argument 1 is.
Argument 2 is B.
Argument 3 is C.
Argument 4 is D.
Argument 5 is E.

Run

Hello.exe lena.jpg

Will get

Argument 0 is hello.exe.
Argument 1 is lena.jpg.

 

 

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.