The main functions can have in it arguments passed which are called as command line arguments. The command line arguments are two in number which are namely:
Argument count denoted by argc and
Argument vector denoted by argv
The argc is an integer variable which denotes the number of parameters passed and argv is pointer to array of character strings.
The syntax is as follows:
main( int argc , char * argv[ ])
{
.......
.....
}
It can also be return as
main(argc,argv)
int argc;
char * argv[];
{
........
.......
}
After the program is executed the first argument entered in prompt would be the name of the program which is to be executed followed by parameters. Sa y for example if the program name of execution is sample and say 3 values are to be passed namely a1,a2,a3 it is given as follows:
sample a1 a2 a3
So in this case argc have value as 3 which is the number of parameters passed and argv would have values as
argv[0]= sample
argv[1]=a1
argv[2]=a2
argv[3]=a3
How to define command line arguments
The main functions can have in it arguments passed which are called as command line arguments. The command line arguments are two in number which are namely:
The argc is an integer variable which denotes the number of parameters passed and argv is pointer to array of character strings.
The syntax is as follows:
It can also be return as
After the program is executed the first argument entered in prompt would be the name of the program which is to be executed followed by parameters. Sa y for example if the program name of execution is sample and say 3 values are to be passed namely a1,a2,a3 it is given as follows:
So in this case argc have value as 3 which is the number of parameters passed and argv would have values as
Profile Answers by GeekAdmin Questions by GeekAdmin
Questions by GeekAdmin answers by GeekAdmin
Related Answered Questions
Related Open Questions