#include <iostream>
usingnamespace std;
int fun (int a, int b=2)
{
return 3*a + 2*b +1;
}
float fun (float a, float b = 2.0)
{
return 3.0*a + 2.0*b + 1.0;
}
int main ()
{
cout << "Enter a number: ";
float x;
cin >> x;
cout << "Result: " << fun(x) << endl;
return 0;
}
a)
float fun (float a, float b = 2.0)
Will be executed because you supply it with a float parameter. The other parameter is a default, so it is optional. Make sense?
b)
11.0
Please work this out for yourself.
c)
In C++, primitives(int, float, long) are passed by value.