An argument, also called command line argument, can be defined as input given to a command line to process that input with the help of given command. Argument can be in the form of a file or directory. Arguments are entered in the terminal or console after entering command. They can be set as a path.
What is a command argument?
Command line argument is a parameter supplied to the program when it is invoked. Command line argument is an important concept in C programming. It is mostly used when you need to control your program from outside. Command line arguments are passed to the main() method.
What are command line arguments with example?
Let’s see the example of command line arguments where we are passing one argument with file name.
- #include <stdio.h>
- void main(int argc, char *argv[] ) {
- printf(“Program name is: %sn”, argv[0]);
- if(argc < 2){
- printf(“No argument passed through command line.n”);
- }
- else{
- printf(“First argument is: %sn”, argv[1]);