Command Line Arguments
Command Line Arguments are the arguments that are specified when the program is executed. We can give multiple arguments on the command line. For example, COPY command of DOS needs two arguments, where the first argument is the name of the source file and the second argument is the name of the destination file.
Use command line arguments
C allows passing value to a program from command line. The values are called command line arguments. All command line arguments are stings, they are interpreted is dependent on how they are used in the program. The most common use of command line arguments is to specify the files on which a program should operate.
Command line arguments are used to run a program DOS prompt. After the program is compiled, linked and the executable file is formed, we run this program by typing the name of the program DOS promot.
e.g. C:> Program_name arguents
C language Q/A
command line arguments passed to main:
As we know that the execution of the program always begins with the main() function. These arguments can be accessed via arguments in the main() function. The C system automatically adds the capability to read these arguments to all C programs.
These are two arguments which are passed to the function main().
The general form of main() with these arguments is:
main (int argc, char*argv[])
The first arguments argc is argument counter (integer type) and holds the total number of entries on the command line, including the program name.
The second argument *argv[] is an array of pointers to strings which holds the individual arguments, argv [0] holds the name of the program, argv[1] holds the first argument, argv[2] holds the seconds argument and so on.