We can modify a program to receive arguments from command line. Example

./a.out string1 string2 string3

Syntax is

int main(int argc, char *argv[])
{
...
}
  • argc (Argument count) is int and automatically stores the number of command-line arguments passed by the user including name of program.
  • argv (Argument vector) is array of char pointers listing all the arguments.
  • argv[0] is the name of the program.
  • argv[1] is the first command-line argument etc.