0

The main function can be called in the following ways in C:

int main()
int main(int argc, char *argv[])

Does C support overloading?
Answer to this question is a NO.

Then how can main() be called in C in two ways?

GSerg
  • 76,472
  • 17
  • 159
  • 346
onlyak
  • 11
  • 6
  • 1
    There can only be one form of main() in a specific program. Which forms that are valid on a given system are determined by the compiler, not by the programmer. – Lundin May 26 '20 at 08:25
  • 1
    The first version actually should be `int main(void)`. An empty parameter list in function definitions is a deprecated feature. – Gerhardh May 26 '20 at 08:29
  • Observe that since only one function is special in this way, a compiler can handle it easily by silently transforming a definition of `int main(void)` into `int main(int _Hidden_argc, char *_Hidden_argv[])`. Then, even if the ABI does not work with routines called with more arguments than parameters in their definitions, it will not matter since `main` is effectively always defined with two parameters (as shown above) and is called that way (by the run-time startup code). The implementation can similarly transform any calls to `main`. – Eric Postpischil May 26 '20 at 08:56

0 Answers0