why in this case we call the function in Main like that " int result = sum(x, y);" why no by just typing sum(x,y)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why in this case we call the function in Main like that " int result = sum(x, y);" why no by just typing sum(x,y)?

11th Mar 2017, 10:46 AM
Matej Čalić
Matej Čalić - avatar
1 Answer
+ 2
Because sum(x,y) would just execute the function and give no output unless there is a cout command in the function whereas int result = sum(x, y); will store the value returned by the function sum in variable result, for further use in the main function.
11th Mar 2017, 11:08 AM
Hitesh Kaku
Hitesh Kaku - avatar