I dont understand why out put is 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I dont understand why out put is 1

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

23rd Mar 2017, 3:59 PM
Zahid Mahmood
Zahid Mahmood - avatar
5 Answers
+ 17
In your comment you've mentioned about calling function with both parameters 😐 So, the correct function call should be sum(x,y) or sum(). The outputs should be 60 and 6, respectively.
23rd Mar 2017, 4:18 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 14
If you make the function call properly, the answer should be 60
23rd Mar 2017, 4:05 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 10
You forgot the braces () after sum: cout << sum() << endl;
23rd Mar 2017, 4:09 PM
Tashi N
Tashi N - avatar
+ 2
thnaks shamima yasmin.
23rd Mar 2017, 4:27 PM
Zahid Mahmood
Zahid Mahmood - avatar
0
shamima yasmin why answer 60 i not use x & y value
23rd Mar 2017, 4:13 PM
Zahid Mahmood
Zahid Mahmood - avatar