Command Line Arguments
Command Line Arguments
Command
Line
Arguments
Command
Line Arguments
Command-line arguments are given after the name of the program in
command-line shell of Operating Systems. To pass command line
arguments, we typically define main() with two arguments:
First argument is the number of command line arguments and second
is list of command-line arguments.
❖ Argv[0] is the name of the program, After that till argv[argc-1] every
Output:
You have entered 3
arguments:
▪ ./main
▪ hello
▪ hi
Properties of Command Line A rguments
a) They are passed to main() function.
invoked.
e) argv[1] points to the first command line argument and argv[n] points last
argument.
Spacing in Command Line A rguments
You pass all the command line arguments separated by a
space, but if argument itself has a space, then you can
pass such arguments by putting them inside
(Double quotes or Single quotes) .
Double Single
Quotes Quotes
Double Single
Quotes Quotes
Double Quotes
When the above code is
compiled and executed with
Single
a single argument separated
by space but inside double
Quotes
quotes.
Single Quotes
Answer: D
Quiz Time
Q. To use command line arguments in C++, how many
parameters are passed to the main function?
a) 1
b) 2
c) 3
d) 4
Answer: B
Quiz Time
Answer: A
Thank You
Arigatōgozaimashita