0

What is command line arguments?

It will be helpful if explain with the example.. About command line arguments used in writing programs

29th Aug 2018, 6:49 AM
Kishan kumar
Kishan kumar - avatar
5 Respuestas
+ 3
command line arguments are the arguments which are pass through command line. They are useful when you want to control your program from outside instead of hard coding.
29th Aug 2018, 7:29 AM
Prateek
Prateek  - avatar
+ 3
Command line arguments are passed to the main() method. int main(int argc, char *argv[]) Here argc counts the number of arguments on the command line and argv[ ] is a pointer array which holds pointers of type char which points to the arguments passed to the program. Example for Command Line Argument #include <stdio.h> #include <conio.h> int main(int argc, char *argv[]) { int i; if( argc >= 2 ) { printf("The arguments supplied are:\n"); for(i = 1; i < argc; i++) { printf("%s\t", argv[i]); } } else { printf("argument list is empty.\n"); } return 0; } Remember that argv[0] holds the name of the program and argv[1] points to the first command line argument and argv[n] gives the last argument. If no argument is supplied, argc will be 1.
29th Aug 2018, 7:33 AM
Prateek
Prateek  - avatar
+ 1
@Noa, you are right :-)
29th Aug 2018, 12:32 PM
Prateek
Prateek  - avatar
0
Thanks bro... M
29th Aug 2018, 7:50 AM
Kishan kumar
Kishan kumar - avatar