+ 1

How output is 66???

#include <iostream> using namespace std; int sum(int a, int b=42) { int result = a + b; return (result); } int main() { int x = 24; int y = 36; //calling the function with both parameters int result = sum(x, y); cout << result << endl; //output 60 //calling the function without b result = sum(x); cout << result << endl; //output 66 return 0; }

12th Feb 2017, 3:55 AM
Saifillah Shuvo
Saifillah Shuvo - avatar
2 Antworten
+ 8
Without specifying second parameter, the default parameter in the function is used for second parameter. Result is 24+42, which is 66.
12th Feb 2017, 4:12 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
since you didn't pass any argument value to the second parameter, it's gonna use the default value that you have assigned to the second parameter in function definition
20th Feb 2017, 4:34 AM
Saami
Saami - avatar