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++

13th Sep 2016, 1:05 PM
subodh Kumar
subodh Kumar - avatar
5 ответов
+ 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; }
13th Sep 2016, 1:32 PM
Zen
Zen - avatar
+ 2
ohkkk
13th Sep 2016, 2:15 PM
Twinkle Baisane
Twinkle Baisane - avatar
+ 1
in c++ ,if we declared one function more than one time is called function over loading
13th Sep 2016, 1:13 PM
Twinkle Baisane
Twinkle Baisane - avatar
+ 1
we can overload main function also.we have to make a class and declare main as a member function in it
13th Sep 2016, 1:30 PM
subodh Kumar
subodh Kumar - avatar
+ 1
thank u
13th Sep 2016, 2:15 PM
Twinkle Baisane
Twinkle Baisane - avatar