Misunderstanding of the main function with command line parameters [Garbage reposted everywhere]

Source: Internet
Author: User

For details, refer to the main function with command line parameters. [reprint]

Http://www.cnblogs.com/xdshennju/archive/2012/01/23/2328992.html

A c program is always executed from the main () function.

Rating: Some C programs do not have the main () function at all.

In the latest c99 standard, only the following two definitions are correct:

(See ISO/IEC 9899: 1999 (E) 5.1.2.2.1 program startup)

Comment: This is a misunderstanding of c99. In c89, the word "only" is true. C99 does not absolutely reject the two forms of main ()

The compiling environment is TC.

Comment: it is nonsense to use the compiler before c89 to discuss the C standard. TC itself also allows main () to contain 3rd parameters. Why not?

If you change return 0; to return 99;

Comments: The C standard only talks about whether main () returns 0 or 1. The Compiler determines the other cases. Here you return 99. Have you ever asked the compiler?

If you write return 99.99 in this way, 99 is returned because the forced type is converted to the integer type before 99.99 is passed to the operating system.

Comments: For things that cannot be reached by the main () operator, the functions with int type are all processed in this way.

The C compiler allows the main () function to have no parameters or two parameters (some implementations allow more parameters, but this is only an extension of the standard ). The two parameters are int type and string type.

Comments: c99 has taken this extension as a standard, so there is nothing to say about "just an extension of the standard ".

"One is string type": There is no string type in the C language, and the C language operates the string through the char * type pointer. Take char ** as a string type. Isn't the C language ready yet?

The system uses spaces to separate strings.

Ratings: there is no reason for failure.

Assign the program name to argv [0], and then assign the first string to argv [1].

Comment: What is "program name "? Argv [0] is actually related to the specific implementation.

"The Last One". Is that true?

Argv [0] ------> C (program name ).

Comment: it is hard to say what this is.

Compile and run. Open the command line and enter D love.txt and press Enter. In this way, open the directory where the d. c file is located, and you will find that there is an additional file named love.txt. After opening it, the content inside is exactly the most widely spoken sentence in the world.

The love.txt file has no relationship with the directory where the d. c file is located. d. c is the source file rather than the executable file. Love.txt should be in the current system directory.

The reason for using command line parameters may be to practice command line usage, So that you need to write a command line-based program in the future. Another advantage is that you can run compiled programs without the need for the c environment.

Running compiled programs has nothing to do with whether to use command line 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.