Function overloading in c++
#include <iostream> using namespace std; void printNumber(int x) { cout << "Prints an integer: " << x << endl; } void printNumber(float x) { cout << "Prints a float: " << x << endl; } int main() { int a = 16; printNumber(a); printNumber(10.0); } In this code, when we write something like printNumber(10.0) , 10.0 will be processed as double ,not float . So there's an error "call of the overloaded function is ambiguous. This is ok. But in the below program, why when we write sum(10.0,n) it runs and there is no problem with 10.0 . Why in this program 10.0 will be processed as double. #include <iostream> using namespace std; void sum(float a, int b) { cout<<"diff="<<a-b<<endl; } void sum(int a,float b) { cout<<"sum="<<a+b<<endl; } int main() { int x=40,n=30; //float y=10.5,m=10.5; sum(10.0,n); sum(x,11.0); return 0; } Can anyone tell the reason please?