I am little new to programming can anyone help me in understanding, what is the point of giving arguments in main() ?
Any help will be seriously appreciated.
int main(void) or int main(int, int) etc.
I am little new to programming can anyone help me in understanding, what is the point of giving arguments in main() ?
Any help will be seriously appreciated.
int main(void) or int main(int, int) etc.
Depending on what type of application you are developing this may or may not be relevant to you. But arguments are intended for your command line arguments that are passed to the application at run time.
The prototype is
int main (int argc, char ** argv);
If you invoke your application from the command line
./a.out foo bar
Then main
will get passed
argc = 2
argv = {"foo", "bar", NULL}
The other valid prototype for main
is
int main(void);
If you don't want arguments. Any other prototype will be rejected by the compiler.
They are generally used for giving command line arguments.