0

How does the following program output 66???

int main() { int x = 24; int y = 36; //calling the function with both parameters int result = sum(x, y); cout << result << endl; //Outputs 60 //calling the function without b result = sum(x); cout << result << endl; //Outputs 66

6th Oct 2016, 5:11 PM
Devansh Kaushik
Devansh Kaushik - avatar
4 Antworten
+ 1
int sum(int a, int b=42) { int result = a + b; return (result); } The default value of b is 42. If you call the function without b then the second parameter will have the default value
2nd Nov 2016, 12:18 PM
Badila Timotei
Badila Timotei - avatar
0
default value of y parameter may be 20
6th Oct 2016, 5:26 PM
Ashraf Ali Mohammed Naji Sinan
Ashraf Ali Mohammed Naji Sinan - avatar
0
can you explain it a bit??
7th Oct 2016, 6:16 PM
Devansh Kaushik
Devansh Kaushik - avatar
0
If the corresponding argument is missing when you call a function, it uses the default value.And the default value was 42,so 24 + 42=66
1st Dec 2016, 10:28 AM
Ivana