0
sorry ,friends i`m not good at english but i still want the answer why first "cout"and last"cout"is 11.4 thanks
#include <iostream> #include <cstdlib> using namespace std; int add(int a,int b=2); double add(double s=3.3,double n=8.1); int main () { cout<<add()<<endl; cout<<add(4,6)<<endl; cout<<add(1)<<endl; cout<<add(3.4)<<endl; cout<<add(1.1,2.2)<<endl; cout<<add()<<endl; } int add(int a,int b) { return a+b; } double add(double s,double n) { return s+n; }
2 Antworten
+ 1
when you call add() no parameter is passed, so the compiler checks for the appropriate overloaded method.
The first add method needs atleast one parameter as it have one default parameter.
The second method can run without passing any parameter using the defaults 3.3 + 8.1 = 11.4
0
thanks for you I think I know it now