Hello and welcome to the and programming language course in the previous session, we talked about functions
as values in this session, we want to talk about the authors functions concept.
Returning multiple values.
In go language, you are allowed to return multiple values from a function using the return, a statement
or in other rules in function.
A single written a statement can return multiple values.
The type of the return values is similar to the type of the parameter defined in the parameter release.
Now you can see the scene techs.
Function, nay, it is the name of the function parameter release, it contains the name and the type
of the function parameters.
Return type list, it's optional, and it contains the types of the values that function returns, if
you are using visa and type in your function, then it necessary to use a written statement in your
function.
Return values.
The function can have one or more returned values assume there is a function, some underscored a veggie
that returns to values, song and average.
Note that when retaining multiple values, the retained value time has to be enclosed within parenthesis.
You can see some pattern for this case.
As a convention, a role is returned as the last argument in a function.
You can see the sample for this case and collecting multiple returned values in the column function
like following Sampat.
Now, go to this good program to illustrate how to use return multiple values.
In this case, we want to calculate rectangular area and perimeter by function, first, create function
for this purpose by the following code.
Right angle, for the example, w Typekit is it and age type of it, is it w an age as parameters by
aid type and set to type as return types and time on it?
First calculate rectangle perimeter for the example three metre column equals tool multiplication W
Class H and calculate rectangle area and in the next line area, calling equals W multiplication hich
now return area and perimeter or variable return area and perimeter.
Now create a main function for invoked the rectangle function, so go to the main function and first
creating local variable definition, then initialization than a comma b type of Disney's teens.
Now calling rectangle function and set return values in two very but a and B as perimeter and area of
rectangle a comma B equals invoke Reagan definition rectangle and set the variables.
For example, 20 and 30 now Display Valley, then go to the next line if P area and a go to the next
line, the perimeter.
And said the reform at the call and save the project and execute the program.
Now we can see the output area is 600 and perimeter is 100.
In the following example, we have a rectangle function that takes two parameters, computes the breakdown
the perimeter and area, and returns on the two values in order not to prolong the time of decision,
we finish it and we will continue the content in the next session.
Goodbye.