0

What is the work or doing of the 'return' statement in the function's body ? To where it returns the value ?

10th Feb 2019, 3:09 AM
kushalpal sharma
kushalpal sharma - avatar
4 Antworten
+ 3
Functions are used to perform certain tasks. If a function is getting input it Should return desired output. Now, return statements are used exactly for that purpose. For example We have a function which add two numbers a and b in C++ language int add(int a, int b){ return a+b; } Here you can see I used return a+b; to feedback output after doing certain operation. You can use that function like this int main(){ int answer = add(5, 5); } So now answer variable will store addition of 5+5 using return method.
10th Feb 2019, 3:19 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 2
When a function returns a value, at time of the function call we need to store that returned value in any variable. In my case function was returning int type value so I stored it in int variable answer. If your function is returning any other data-type you need to use that type of variable to store returned value.
10th Feb 2019, 3:25 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
Ok thanx
10th Feb 2019, 3:31 AM
kushalpal sharma
kushalpal sharma - avatar
0
So where does it return the value ?? The main function?
10th Feb 2019, 3:22 AM
kushalpal sharma
kushalpal sharma - avatar