Can main() be overloaded?

QuestionsQuestions8 SkillsProCreate "Hello World" In CNov, 21 2025
083

No, the main() function cannot be overloaded in C or C++. The language specifications require that there is only one main() function in a program, which serves as the entry point. Overloading is a feature that allows multiple functions to have the same name with different parameters, but this does not apply to main().

In C and C++, you can only define main() in one way, either as:

int main() {
    // code
}

or

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

Any attempt to overload main() will result in a compilation error.

0 Comments

no data
Be the first to share your comment!