+ 2

Can someone explain this?

How did the vale of x became 66? https://code.sololearn.com/244/#cpp

17th Jan 2018, 11:30 AM
Abhay Shukla
Abhay Shukla - avatar
3 Answers
+ 4
In this program the function 'sum' is defined with two parameters. And the second parameter has defined a default value. It is 42. Now, when you call the function from main you can pass the both two argument or you can only pass a argument. So, if u call that function with only 1st argument then then it will use default value for b and will return (1st value+42). So when you call the function with only x's argument 24, it returns (24+42)= 66.So in this way it become 66. But if u pass both argument, it will not use default argument.
17th Jan 2018, 12:04 PM
Jogoth Paul
Jogoth Paul - avatar
0
The function sum is defined in a way that if you don't pass a second value, the default is 42 and the return is the first value + 42. So, you do sum(x) with x = 24, then it returns 24 + 42 = 66
17th Jan 2018, 11:36 AM
SebastiĂĄn Zapata
SebastiĂĄn Zapata - avatar
0
Thank you both...
17th Jan 2018, 12:12 PM
Abhay Shukla
Abhay Shukla - avatar