job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

Why is no argument passed in main function c++?

This question already has an answer here:

  • Pass arguments into C program from command line 6 answers

Whenever we define main() function in any code, why don't we pass any argument in it?

c++ c

The C++ standard sanctioned variations of main() are:

int main () { body }
int main (int argc, char *argv[]) { body } 

The C standard sanctioned variations of main() are:

int main (void) { body }
int main (int argc, char *argv[]) { body } 

There are other platform-specific variations, but all of them must return an int.

It appears that you have only seen programs that use the first version of main(). Most real-world applications use the second version of main(). It allows them to process command-line parameters.

  • 1
Reply Report


Related Questions

Trending Tags