C Command Line Arguments

In C Programming Language we have built in support for “Command Line arguments”. Command line arguments allows us passing the parameters to the C Program’s main() function when the are executed. We can pass the parameters from the command line itself.

Below is the prototype for main() when it is suppose to accept command line arguments –


There are two parameters passed to main() function.

  • int argc
  • char *argv[]

The first parameter, argc is an integer which is used to define the number of parameters passed to main(), and the second parameter is argv, is an array of pointers to character strings which is consist of the list of these parameters. Each argument on the command line is separated by

The program name will be stored in the first item in argv, followed by the list of the parameters. If the program name is followed by n parameters there will be n + 1 element in argv, ranging from argv[0] to argv[n]. argc will be automatically set equal to n + 1.

Example :

Assuming that the executable is called hello.