Reputation: 77
If I write a function such as this:
void myfunc(const int argc, const char *argv[])
Will argc and argv automatically get their values from command line arguments, or will they need to be passed in their values from main?
Upvotes: 1
Views: 5741
Reputation: 36391
Argument names are not significant per se. You can write main like this:
int main(int count, char *array[]) {...}
if you like. main
is a special function because it is the default entry point of a C program and that command-line arguments values are passed to it, that's all.
Declaring/defining a function as:
void myfunc(int argc,char *argv[]) {...}
is exactly the same as:
void myfunc(int foo,char *bar[]) {...}
and such a function can be called from any (possible) point you like with any (acceptable) values you like.
Upvotes: 3
Reputation: 58848
No, nothing special happens if you call a function's arguments argc
and argv
. The caller has to pass them, like any other arguments.
Upvotes: 3
Reputation: 6003
argc and argv must be passed, such as:
int main(int argc, char *argv[])
{
myfunc(argc, argv);
return(0);
}
Upvotes: 3