INPUT ARGUMENT IN MAIN FUNCTION

Could anyone please explain me easily what
exactly the main function input arguments, in
both ways,

1
2
int main(int argc, char* argv[]) {
int main(int argc, char** argv) {


do?
both signatures are the same

argc is the number of arguments passed to the program, from command line
argc can have values >= 1, first argument is always the name of the program itself.

argv is the array of command line arguments passed to the program. argv[0] is always the name of the program. argv[1] onwards are the actual parameters passed

example
prompt> testprog argu argument


In this case the argc = 3 argv[0] = testprog argv[1] = argu argv[2] = argument
so:

- I am gonna need these arguments only to launch the program from the command line

- If I donĀ“t plan to launch the code from command line I can write the main function without any arguments, like

int main() {...

right?
You may define main either as having two parameters or having no parameters or in implementation-defined manner.
If you do not need parameters then you may define main without them.
thanks a lot to both of you!
Only take into account that the following statement of @codewalker

argc can have values >= 1, first argument is always the name of the program itself.


is invalid. argc can be equal to zero.
Topic archived. No new replies allowed.