Knowledge Base
Home C

How to define command line arguments

Category: C | Comments (0)

The main functions can have arguments passed which are called as command line arguments. There are two command line arguments:

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 returned 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. Say 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


Next: How to develop compile and run a C program




Post Comment


Members Please Login

Name:


Email:
 
(Optional. Used for Notification)

Title:

 
Comment:


Validation Code:
 <=>  (Enter this code in text box)
Subscribe





Daily Email Updates

Get Latest Knowledge Base Updates delivered directly to your Inbox...

Enter your email address:

Latest Knowledge Base Updates
 

C Tutorials

 

Related Tutorials