Command Line Argument

There are three types of declaration we can write it:

  1. User-Friendly:
int i;
scanf("%d",i); //here compiler will waits for user input

2. OS-Friendly:

int i = 7;
//it directlly takes i = 7 as a will not wait for user input

3. Local Time:

  • Here command line arguments will come in picture. What is it? will try to understand in this blog post.

While we are taking input from CMD:

main(int argc, char **argv)
//we have to change the main function prototype
//use in system programming

Here argc holds a number of argument, we are providing through the command line, including the executable file name.

Here argv holds the base address for array pointer, where command line arguments there.

For example :

main(int argc, char **argv)

//here while compiling a program we need to give arguments like below examples

answer : argc = 1

username@systemname$./a.out 10 20
answer : argc = 3

username@systemname$./a.out "abc_def"
answer : argc = 2
  • Whatever the type of data we are passing through command line those are treated as a String.



Leave a Reply


You are commenting using your account. Log Out /  Change )

Google+ photo


Twitter picture


Facebook photo



Connecting to %s

Powered by

Up ↑

%d bloggers like this: