Doubt reguarding return type | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Doubt reguarding return type

The called functions return type is returning one value return(x) while our function in main has sum_up(x,y) two value how is it possible? https://code.sololearn.com/cl52GMdn7iu5/?ref=app

4th Apr 2019, 11:29 AM
Unemployed Visionary.
3 Answers
+ 4
One more important thing to say about your program... You asked there are two values x and y in function... They are nothing but just parameters or values that your function sum_up(); is gonna use.. This is not necessary that the function accepting 2 parameter must return 2 values ( a function can return only one value when called) .. In fact there can be a function which even don't return something or don't even receive any parameters ...
4th Apr 2019, 12:18 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 4
The answers is simple. Your function sum_up(); is taking to parameters x and y.. In function defenition you have written line ... x+=y; It means same as x=x+y; Again it means you are getting sum of x and y in variable x.. And therefore you are returning the calculated value to main function using return (x) ; Again you are assigning this returned value to variable ' result ' so result gets value of sum of x and y... and hence your program works.. Hope it will help you😊
4th Apr 2019, 12:04 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
Thankyou bro! your help means a lot to me. I really appreciate it. Its people like you who think for the greater good of this community make me more happy to code.Your an inspiration bro!
4th Apr 2019, 1:16 PM
Unemployed Visionary.