Return Functions
The Function that Gives Output According to The Input Provided. These are known as Return Function.
Syntax
The return statement can be used to return the value to a function call.
The return statement denotes that the function has ended. Any code after return is not executed.
Example 1
First, We will make a program to add 2 numbers.
Explanation :
All Parameters defined inside a () can be accessible inside Function Scope i.e. only inside { } Parenthesis.
Example 2
Lets Assume, You have to convert Temperature (Fahrenheit to Celsius)
What you will do (Generally) :
Either you will create a variable and assign the value of Temperature in Fahrenheit
so, now we will use the 1st method.
Now, We will do the same task using the functions to make that function reusable and look our program clean.
Here, We have created a function with the name toCelsius( ) to convert Fahrenheit to celsius.
Whenever toCelsius(f) is called with Fahrenheit value as a parameter, it will output the converted celsius value using the return statement.
Then we can use returned value where ever we need. for example we have used the returned value to print in the console tab.