C++-Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++-Question

//C++ double foo(double x, double y){ return x * y; } int foo(int x, int y){ return x + y; } int main(){ std::cout << foo(3, 8); return 0; } //Can somebody explain to me why the output is 11, not 24?

7th Aug 2018, 5:32 PM
DarkEye
DarkEye - avatar
3 Answers
+ 4
It is concept called function overloading. Means you can have function with same name but different number of parameters or same number of parameters of different data types. You are passing int values so function having such parameter will be called and you will get 11 as answer. Try passing 3.14 and 3.14 as argument and see the result. Hope this helps ☺️☺️.
7th Aug 2018, 5:43 PM
Meet Mehta
Meet Mehta - avatar
7th Aug 2018, 5:44 PM
Meet Mehta
Meet Mehta - avatar
0
thank you both, have a nice day
7th Aug 2018, 7:46 PM
DarkEye
DarkEye - avatar