C Command Line Arguments

Command line arguments are passed inside the main function of a C program also called as command line of the C program, hence the name, command line arguments.


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

  • Argc: This is a mandatory parameter that counts the number of arguments.
  • Argv[]: This is also a mandatory parameter that contains all the arguments.


#include <stdio.h>  
void main(int argc, char *argv[] )  
printf("File name: %s\n", argv[0]);  
if(argc < 2)
      printf("No argument passed.\n");  
      printf("Argument 1: %s\n", argv[1]);  


File name: C_program
Argument 1: welcome
Please follow and like us:
Content Protection by DMCA.com