sorry ,friends i`m not good at english but i still want the answer why first "cout"and last"cout"is 11.4 thanks | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

1st Aug 2017, 1:12 PM
彭杰
彭杰 - avatar
2 Answers
+ 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
1st Aug 2017, 1:26 PM
Da' BO$
Da' BO$ - avatar
0
thanks for you I think I know it now
1st Aug 2017, 1:35 PM
彭杰
彭杰 - avatar