0
what will be output?? #include <iostream> using namespace std; int main(int a) { cout << a << "\n"; return 0; } int main(char *a) { cout << a << endl; return 0; } int main(int a, int b) { cout << a << " " << b; return 0; } int main() { main(3); main("Subodh"); main(9, 6); return 0; } if output is compilation compilation error then how can we overload "main" function in C++
5 Respostas
+ 3
As Twinkle said, you can only have one main function in your program, but you can otherwise have several functions with the same name and return value but different parameters (= function overloading).
#include <iostream>
using namespace std;
void sub(int a) {
cout << a << "\n";
}
void sub(const char *a) {
cout << a << endl;
}
void sub(int a, int b) {
cout << a << " " << b;
}
int main(void) {
sub(3);
sub("Subodh");
sub(9, 6);
return 0;
}
+ 2
ohkkk
+ 1
in c++ ,if we declared one function more than one time is called function over loading
+ 1
we can overload main function also.we have to make a class and declare main as a member function in it
+ 1
thank u