Sunday 21 January 2018

Command Line arguments


Command Line arguments

Command Line arguments
Definition: It is a parameter supplied to a program when the program is invoked.These are the
arguments passed to the main at command prompt.

Explanation:

main() function in 'c' takes two arguments called argc,argv.The information contained in the command arguments ,when main is called up by the stream. argc: The variable argc is an argument counter that counts the number of arguments on the command line.

argv:  The argv is an argument vector and represents an array of character pointers that point to the command line arguments.The size of array will be equal to argc.



   Ex: c:\> program x-file y-file

      here argc=3.
           argv[0]= program.
           argv[1]=x-file.
   argv[2]=y-file.
i.e.., here argv[0] contains the base address of string
"program"  argv[1]  contains the base address of string
"x-file"   argv[2]  contains the base address of string
"y-file"
  Therefore arguments that we pass to main at command prompt are command line arguments.

Advantages of command line arguments:

1.There is no need to recompile the program everytime we want to use this utillity.It can be executed at command prompt.

2.Once executable file is created nobody with malicious intention can tamper with your source code program.

3.We can pass source file name and target file name to main(), and utillise them in  main().

0 comments:

Post a Comment