C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 1)
1.
What will be the output of the following program?
#include<iostream.h>
long BixFunction(int x, int y = 5, float z = 5)
{
return(++x * ++y + (int)++z);
}
int main()
{
cout<< BixFunction(20, 10);
return 0;
}
Discussion:
16 comments Page 1 of 2.
Rajat Ravi said:
1 decade ago
Solution:
x = 20.
y = 10.
z = 5.
++x = 21.
++y = 11.
++z = 6.
21*11+6 = 237.
x = 20.
y = 10.
z = 5.
++x = 21.
++y = 11.
++z = 6.
21*11+6 = 237.
(6)
Ameet said:
1 decade ago
x and y always refer the current value passed into 2nd fun so x will become 20 and y become 10. Whenever the pointer goes into the return that time x will become 21 and y will be 11 and z will be 6.21*11+6=237 that is final answer.
(1)
Aish said:
1 decade ago
See in float z = 5.0 then in int z = 5 we can take like this. I am right?
(1)
Sindhu said:
8 years ago
What does the Bixfunction (20, 10) mean ?
If it indicates x=20, y=10, but y=5 was given in declaration ?
If it indicates x=20, y=10, but y=5 was given in declaration ?
(1)
Srijan s said:
4 years ago
I think there will be an error as there are only two parameters passed where as in function definition we can clearly see there are 3 variables.
(1)
Ranjith said:
1 decade ago
Please any one explain me, how this method takes two arguments?
Bala said:
1 decade ago
Here from the main function,
x=20,
y=10,
z=5 (as it is from the function definition)
So the computation for
(++x * ++y) + ++z
goes like
++x = 21
++y = 11
21*11 = 231
++z = 6
231 + 6 = 237.
x=20,
y=10,
z=5 (as it is from the function definition)
So the computation for
(++x * ++y) + ++z
goes like
++x = 21
++y = 11
21*11 = 231
++z = 6
231 + 6 = 237.
Arunakiri said:
1 decade ago
Default arguments pass the values from right to left order in called function.
Vicky said:
1 decade ago
Actually here in the main function the function called bixfunction is being called upon by invoking 2 arguments which won't happen because the bixfunction has 3 arguments to set it to operate for the values being sent to bixfunction. So the program will terminate due to calling a function which is not available.
Dev said:
1 decade ago
There is "No ERROR" and 237 is the correct answer described by '@Bala'.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers