Why do we have parameters in main function?

we never used the parameters used in main function? then why have it?

Hi @JAIDEEP_C
It totally depends upon you whether you have parameters in main function or not. Basic idea behind these parameters is that we pass them when we want to use command line arguments (that is we can pass all the inputs using command line).

int main(int argc, char *argv) { / … */ }

  1. argc (ARGument Count) is int and stores number of command-line arguments passed by the user including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for argument and one for program name)
  2. The value of argc should be non negative.
  3. argv(ARGument Vector) is array of character pointers listing all the arguments.
1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like