answersLogoWhite

0


Best Answer

The argc and argv identifiers in a (standardly declared) main function allow access to the command line arguments. The standard declaration is...

int main (int argc, char *argv[]) ...or... int main (int argc, char **argv)

The number of arguments is stored in argc. Since the name of the program is, by convention, always implicitly the first argument, then argc is always at least 1, even if there are no arguments.

Each argument, then, is stored in argc[i], where i ranges from 0 to argc-1. The name of the program is stored at argv[0], and further arguments are argv[1], argv[2], etc.

Normal convention is that each white space separated word on the command line is an argument. The exception is in the case of a quoted argument, in which case the entire quoted string, minus the quotes, is a single argument.

Is is an error to attempt to write to any argument. If parsing by side effect parsers, such as with strtok(), is to be done, a copy of the argument must be made.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the work of argc and argv in c program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Are the variables argc and argv are local to main?

Answeryes they are local to mainAnswerargc and argv can be used as variable names anywhere in a C program. If they are declared as arguments to main() then they are local to main:int main(int argc, char *argv[]){// argc and argv are local to main in this short programreturn 0;}


Example program arrays in turbo c plus plus?

Yes, you can use for-loop in a C program compiled by Turbo C.


What is the purpose of the parenthese following the world main in a c program?

The parentheses following the word main in a C or C++ program introduces the argument list for the call to main. The standard prototype is... int main (int argc, char *argv[]); ...where argc is the number of words on the command line, and argv is an array of pointers to arrays of null terminated arrays of characters, one for each white space delimited word on the command line. If you said `myprog this is a test` you would get argc = 5 argv[0] = "myprog" argv[1] = "this" argv[2] = "is" argv[3] = "a" argv[4] = "test"


What is a valid heading for the main program?

For a 'C' program, the main routine must be on of these:int main (void)int main (int argc, char ** argv)int main (int argc, char ** argv, char **envp) /* on some platforms */


What must every c program have?

A main function must be present in every C program.


Program using putstr function in pointer in c?

#include <stdio.h> int main (int argc, char **argv) { puts (argv[0]); return 0; }


What does the C and V in argc and argv stands for?

count, values


What do the 'c' and 'v' in argc and argv stand for?

c for count v for vector


C program to find the perimeter of rectangle?

#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv){ if(argc != 3){ printf("Gimme two dimensions\n"); }else{ printf("The area is %i\n", (atoi(argv[1]) + atoi(argv[2])) << 1); } return 0; }


How is the main function called in a 'c' language program?

There is no default argument to the main function in C. Every C program must have one (and only one) main function. The standard dictates that the main function may have either of the following definitions: int main (void) {/*...*/} int main (int argc, char** argv) {/*...*/} The first version is used when your program does not require any command-line switches. Note that int main () is an acceptable declaration of the main function in both C and C++, but is not a valid definition in C. Note also that, in C, the return type may be declared void, but not in C++. The second version is more common. The argc argument holds the count of all arguments in the argv array and is always at least one. The argv argument refers to an array of char pointers to null-terminated character arrays thus all arguments are strings. Thus the value 42 will be passed as the string "42". The first element, argv[0], is always the fully-qualified path to the program executable (hence argc is always at least one). As well as allowing your program to determine its physical location upon the system, it allows your program to determine its given name even if the user has renamed your executable. This is useful when printing error messages. Any additional arguments passed from the command-line will be found in elements argv[1] through argv[argc-1]. The final element, argv[argc], is always nullptr.


What do the c and v in argc and argv stand for?

The letter "c" in argc stands for count. The letter "v" in argv stands for vector. You can visit this website for more info.......... http://www.dgp.toronto.edu/~ajr/209/notes/argv.html


How do you write c file arguments?

Using parameters argc and argv, and library functions fopen, fprintf, fclose