+ 1
I have doubt in the output generated
5 Réponses
+ 4
you are passing x(for a) whose value is 24 and b=42
in function
result=x+y=24+42=66
and then the result variable returns and its value get store in variable result (in main)
result=sum(x); which is as same as result=sum(24);
+ 1
What’s the function, the expected output, and the actual output?
+ 1
the second function whose output is 66
+ 1
What’s the code of the function?
+ 1
#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;
//calling the function without b
result = sum(x);
cout << result << endl;
return 0;
}