I know that to use command line arguments in C you do something like this:
int main(int argc, char **argv)
{
//use argc and argv
}
Today I was thinking about it and I realized I have never not seen them called argc
and argv
. Is it a requirement that they are called this or is it just convention? If it is required why is this the case?
Could I do something like this:
int main(int length, char**myinput){
//use length as you would argc and myinput
// as you would argv
}
I haven't had a chance to write a program to test it out yet.
The C standard says that you can call them whatever you want.
5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared): [..]
In What does int argc, char *argv[] mean?, answerer meager says that argc
and argv
are named so by convention (argument count and argument vector respectively).