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

Source: Internet
Author: User

(1) The first int represents the return value of the entire main function, and if the function is executed normally, returns 0, and the exception returns 1.

(2) int ARGC represents the total number of command line parameters, since is the number, that is the integer type, that is: int;

(3) char* ARGC representative program under the Linux terminal parameter assignment, the passed parameters will be saved to argc[] character array;

(4) When the value is passed, the different parameters are separated by a space (this is the rule);

(5) When the value is passed, the first parameter is assigned to ARGV[1], when the value is passed, the second parameter is assigned to ARGV[2], and when the value is passed, the third parameter is assigned to ARGV[3] ...;

(6) Argv[0] represents the file name and path name of the program (the individual expresses the understanding on the line, do not delve into);

(7) After the pass value is finished, press ENTER, at this time ARGC will recognize the number of parameters;

Attach code and procedures:

1#include <stdio.h>2 intMainintargcChar*argv[])3 {4 inti;5printf"argc =%d\n\n", argc);6  for(i=0; i<argc;i++)7 {8printf"argv[%d]:%s\n", I,argv[i]);9 }Ten  One return 0; A}

1#include <stdio.h>2 intMainintargcChar*argv[])3 {4     intI=0;5      while(i!=3)6     {7printf"argv[%d]:%s\n", I,argv[i]);8i++;9     }Ten  One     return 0; A}

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

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.