New course! Every coder should learn Generative AI!
Try a free lesson0
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?
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 ☺️☺️.
0
thank you both, have a nice day