Command line arguments in C/C++

In a program the most significant function is the main() function. It is defined with a return type of int and without arguments

 int main()

  {

    /* … */

  }

Command-line arguments are typically the arguments given to the main function.It includes two arguments the first argument is the number of command line arguments and second is list of command-line arguments.

 int main(int argc, char *argv[])

  {

          /* … */                 

  }

argc (argumented Count)-> is of type integer and includes the count of number of arguments including the program name.Therefore if we pass a single argument,the count of argc will be 2 (one for argument and one for program name).The value of the count cannot be negative.

argv (argumented Vector)->is array of character pointers listing all the arguments.

Properties of Command Line Arguments:

These arguments passed to main() function.

These are parameters/arguments supplied to the program when it is   

invoked.

  • argv[argc] is a NULL pointer.
  • argv[0] holds the name of the program.
  • argv[1] points to the first command line
  • argument and argv[n] points last argument.

Note : Command-line arguments are separated by a space, but if the argument itself is space then we should pass such arguments by putting them inside double quotes ” or single quotes ”.

Enquire Now

Enquire Now

Enquire Now

Please Sign Up to Download

Please Sign Up to Download

Enquire Now

Please Sign Up to Download

Enquiry Form

Quick Enquiry