Check the number of parameters if (argc Īrguments and parameters are strings passed to your program to give it information. In a program without the capability to parse its command-line, main is usually defined like this: Every C and C++ program has a main function. Having a program run without user interaction - this is especially useful for programs that are called from scripts or other programs.Īdding the ability to parse command-line parameters to a program is very easy.Modifying program behaviour - command-line parameters can be used to tell a program how you expect it to behave for example, some programs have a -q (quiet) option to tell them not to output as much text.The uses for command-line parameters are various, but the main two are: Exactly how this is done is beyond the scope of this article (on Windows, look up CreateProcess on UNIX and UNIX-like systems look up fork(3) and exec(3) in the manual). The user types a command and the shell calls the operating system to run the program. Command-line parameters are passed to a program at runt-time by the operating system when the program is requested by another program, such as a command interpreter ('shell') like cmd.exe on Windows or bash on Linux and OS X.