+ 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; }
2 ответов
+ 8
Without specifying second parameter, the default parameter in the function is used for second parameter. Result is 24+42, which is 66.
+ 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