Lets say if we want our program to work with other programs and other program call our program. Then just like how we provide arguments in function call; we can call our program and the arguments can be given using the command line.
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]){
int arr[5] = {1,2,3,4,5};
printf("the argument number of of main argc : %d\n",argc);
printf("The first argument : %s\n",argv[1]);
return 0;
}
argc contains the number of argument passed to the main function.
argv is the argument vector. Contains the argument given from index 1 and above.
index 0 of argv is the file name of the function.
Leave a Reply