Using argc and argv
While we could give alternate names for the argc
and argv
parameter names, we will use these two names throughout this chapter for consistency.
When we invoke a program, we now see the following:
- Memory is allocated in the program space.
- Command-line arguments are processed into function parameters passed into
main()
, or ignored if those parameters are absent. - The execution begins with a call to
main()
.
The first thing to note is that every argument from the command line is broken up into strings. A pointer to the beginning of each string is placed in argv
, and the argc
counter is incremented. In many cases, string input is sufficient without any further processing. We will explore converting string input into other values in the next chapter, Chapter 21, Exploring Formatted Input.
The program name itself is always placed in argv[0]
. Therefore, ...