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?

3
  • 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. Commented May 26, 2020 at 8:25
  • 1
    The first version actually should be int main(void). An empty parameter list in function definitions is a deprecated feature. Commented May 26, 2020 at 8: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. Commented May 26, 2020 at 8:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.