The use of command-line arguments for C + + main functions

Source: Internet
Author: User

The most important feature of C programs is that all programs are assembled using functions . Main () is called the main function , which is the entry for all programs to run. The rest of the functions are either a parameter or no parameter, which is called by the main () function or other general function , and if a parameter function is called, the argument is passed at the time of invocation.

  The main function in C + + language, often with parameter argc,argv, is as follows:

int main (int argc, char** argv) int main (int argc, char* argv[]) contains an integral type and an array of pointers from the form of the function arguments . When the source program is compiled and linked, the extension is generated. EXE executable file, which is a file that can be run directly under the operating system, in other words, is started by the system to run. Since the main () function cannot be called and passed by other functions , only the

  The system passes parameters when it starts running .

In an operating system environment, a complete run command should consist of two parts: the command and the corresponding parameters . The format is:

  Command parameter 1 parameter 2 ... parameter n?

This format is also known as the command line. commands on the command line are the file names of the executable file, followed by a space-delimited argument , and a further complement to the command , which is passed to the main () function . Parameters .

  The command line has the following relationship to the parameters of the main () function :

Set command behavior: program str1 str2 STR3 STR4 STR5

Where program is the file name, which is a compiled by PROGRAM.C, linked to the generated executable file Program.exe, followed by 5 parameters . For the main () function , its parameter ARGC records the number of commands and arguments in the command line, a total of 6, the size of the pointer array is determined by the parameter the value of ARGC is determined, that is, char*argv[6], and the value of the array of pointers is shown in 6-15.

Each pointer to an array points to a string, respectively. It should be noted that the pointers to the array of pointers received are from the CommandThe start of the line received, the first received is Command, then it is Parameters

"Reprint" http://verydemo.com/demo_c92_i110439.html

The use of command-line arguments for C + + main functions

Related Article

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.