6.2.5. main
: Handling Command-Line Options
It turns out that main
is a good example of how C++ programs pass arrays to functions. Up to now, we have defined main
with an empty parameter list:
int main() { ... }
However, we sometimes need to pass arguments to main
. The most common use of arguments to main
is to let the user specify a set of options to guide the operation of the program. For example, assuming our main
program is in an executable file named prog
, we might pass options to the program as follows:
Exercise 6.21: Write a function that takes an int
and a pointer to an int
and returns the larger of the int
value or the value to which the pointer points. What type should you use for the pointer?
Exercise 6.22: ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.