C Programming - Command Line Arguments - Discussion


According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?

int main(int argc, char *argv[])
int main(argc, argv)
int argc; char *argv;
int main()
    int argc; char *argv;
[D]. None of above

Answer: Option A


No answer description available for this question.

Sagarborse said: (Sep 12, 2010)  
Option A is correct
option B is Dennis Ritchie style/pattern of declaring function
option C have local variables instead of command-line arguments
option D no issues / no comment

Karthik said: (Feb 3, 2011)  
In unix A option style is used
in turbo-c B option style is used
but they were same
argc is used for count;//argument count
argv is used for storage of variable type;//argument variable

Sam said: (Aug 8, 2011)  
Nice explanation.

Prashant said: (Feb 3, 2012)  
Option A is correct .

int argc specifies number of arguments
and the char *argv[] is a pointer array which holds the adress values of all the command line arguments(inputs).

Samadhan Adate said: (Feb 22, 2012)  
Option A is correct bcz when you pass the arguments to any function you must have to specify the argument type(int,flot,char and so on)to hold the value of that type which is passed from the command line..first argument-to count number of arguments.second pointer array argument to hold actual passed values in array.

In option B that is not right definition of function where argument type is missing..

In option C there is no any arguments passed to main(),main() has two local variables..

Option D is wrong bcz option A is correct Answer.

Chandan Gupta said: (Jul 17, 2013)  
No doubt Option (A) is right. In respect to command line Argument in c main() function takes two arguments First argument is argc which stands for argument count -it count the no of arguments which are given at the time of execution and argv is an array which stores the argument entered at command line.

Vimal said: (Jul 11, 2016)  
What is meant by ANSI?

Doselect said: (Jan 17, 2017)  
American National Standards Institute: ANSI.

It's international standard.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.