command line arguments
command line arguments
C–
So far, we have seen that no arguments were passed in the main
function. But the C programming language gives the programmer
the provision to add parameters or arguments inside the main
function to reduce the length of the code. These arguments are
called Command Line Arguments in C.
In this tutorial, we will discuss:
cl.c
// The program name is
#include<stdio.h>
int main(int argc, char* argv[])
{
printf("Welcome to DataFlair tutorials!\n\n");
int i;
printf("The number of arguments are: %d\
n",argc);
printf("The arguments are:");
for( i = 0; i < argc; i++)
{
printf("%s\n", argv[i]);
}
int sum=atoi(argv[1])+atoi(argv[2])
+atoi(argv[3]);
return 0;
}
Code on Screen-
Output-
C:> ./a.out 10 20 30 hello hai how are you