0
What is the work or doing of the 'return' statement in the function's body ? To where it returns the value ?
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.
+ 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.
+ 1
Ok thanx
0
So where does it return the value ?? The main function?