Is there any standard for the format of a program argument?

int main(int argc, char **argv)
{}

      

  • Is it possible that argc

    is 0?

  • Should argv[0]

    be the name of the executable?

  • Is there any standard for these problems?

+3


source to share


2 answers


  • Yes.

  • Usually yes, it can also be empty or some other identifying string or even NULL

    (see my appendix). You can also change argv[0]

    to something else from within the program.

  • C (and C ++) specifications.

You also missed one: the last element in argv

always NULL

, that is, argv[argc]

always will be NULL

.




In the C11 spec, this is in Β§5.1.2.2.1. Launching the program.

In the C ++ 11 specification, its main function is Β§3.6.1.

+6


source


  • Yes
  • Not. Argv [0] does not have to exist, but if it does, it is the name of the program as it can be retrieved.
  • I assume this is a standard in C, Cpp. @JonathanLeffler linked a great answer.


+1


source







All Articles