Consider the following function definition:
void defaultParam(int u, int v = 5, double z = 3.2)
{
int a;
u = u + static_cast%26lt;int%26gt;(2 * v + z);
a = u + v * z;
cout %26lt;%26lt; "a = " %26lt;%26lt; a %26lt;%26lt; endl;
}
What is output of the following function calls?
a. defaultParam(6);
b. defaultParam(3, 4);
c. defaultParam(3, 0, 2.8);
C++ help please?
I provided tracing steps so you can understand what is going on.
a: u = 6, v = 5, z = 3.2
u = 6 + int(2 * 5 + 3.2) = 6 + 13 = 19
a = 19 + 5 * 3.2 = 19 + 16 = 35.
"a = 35"
b: u = 3, v = 4, z = 3.2
u = 3 + int(2 * 4 + 3.2) = 3 + 11 = 14
a = 14 + 4 * 3.2 = 14 + 12.8 = (int) 26.8 = 26
"a = 26"
c: u = 3, v = 0, z = 2.8
u = 3 + int(2 * 0 + 2.8) = 3 + int(2.8) = 5
a = 5 + 0 * 2.8 = 5
"a = 5"
Reply:Dude. Why don't you just type it in, compile it, and run it with those arguments??? Do you own homework!
Reply:Plug in the numbers.
With out a call just using what is in the parameters, I get 29.
So, substitute the 6 for the u and do the math
then etc.....
Reply:You may also post your homework question at websites like http://homeworkhelp.co.in/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment