Hello and welcome to the golden programming language course in the pedigree session, we talked about
returning multiple values.
And in this session, we want to talk about the others fonctions concept.
Function arguments.
Ingo language, the parameters passed to a function are called actual parameters, various the parameters
received by a function or can't form on parameters by default, go language use can't by value method
to pass arguments in function go language support.
Two ways to pass arguments to your function First is card by value and second is called by reference.
Caused by value, the call by value method of passing our humans to a function copies the actual value
of an argument into the four parameter of the function.
In this case, changes made to the perimeter are inside the function have no effect on the arguments.
By default, go programming language users can't buy value to pass arguments in general.
This means that code within the function cannot alter arguments used to call the function.
Now go to this code and illustrate how to use card by value.
First, creating a swap function that takes two parameter and changes, then together.
Fine, for example, swept
the X and Y is in type and return type, is it?
First creative and Van Claire Typekit did.
And said the venue of its intent.
Ten equals X and put Y value already then into X X equals Y and now put tenth into Y Y equals 10th and
return 10.
Variable value retailer can reformat the code and save the project.
Now create the main function for involved the function, so go to the main function.
First, creating local variable definition and initialization for the example that A.
E equals a hundred and go to the next line and second variable definition Van B Typekit is into gain
equals 200.
These play these very the B force swap if F.
The four swap a equals persons, the and B equals Person D and said they were a.
Now calling it soft function to slap these values.
Swap and pass value that A and B to it, A and B.
Now displayed these very able after swap if they're after swap.
A gladiator equals personality.
And B, that evil equals personality and set the very ideals A and B again reformat the code, save
the project and execute the code.
Now we can see the output before Super eight equals 100 and B equals 200.
And after Super eight equals 100 and again, B equals 200.
It shows that there is no change in the values, although they had been changed inside the function.
In this parameter passing method, values of actual parameters are copied to functions for more parameters,
and the two types of parameters are stored in different memory locations.
So any changes made inside functions are not reflected in actual parameters of the color.
Now go to a slide and continue.
Second, call by reference, the code by reference missal of passing our unions to a function copies
the address of an argument into the form on perimeter inside the function.
The address is used for access to actual argument used in the Con.
This means that changes made to the perimeter affect the past argument to pass the venue by refis.
Argument pointers are passed to the function just like any other value.
Now go to this school and illustrate how to use called by reference.
First to your last go.
They have the project and ready to ride.
First, we need to declare the function parameters as points four times as in the following function
swap, which exchange the values of the two integer variables, pointing to why its arguments, for
the example formed.
Swapped and set the variable X and the type of it is prone to treat as received.
And very even why Asterix and the time of the this point of into.
Defined the 10 variables that can talk about it ain't go to the next long and save the value and address
X terms equals x three x x.
And put Y into X cone to X equals to Y.
Now put 10 variable into Y value that as six Y equals 10.
Reformat the code and save the project, now, create the main function for each of the search function,
so go to the main function first, creating local variable definition and initialization for the example,
via a m equals a 100 and go to the next line.
That be it equals 200 now this these variable default swap for the example that a
default swap A equals Person D and the equals Person D and set by either A and B, you go to the next
line and calling the function to swap the values, swap and set the variable A and B as a pointer and
assign a common Anderson B.
And percent, a indiqué pointer to a means address of variable A..
And Ampersand B indicates pointing to A to B means ad to solve variable B now displayed these variable
after slope.
If F after such a equals, Person D and B equals first in the set.
The letter A and B.
Now reformat the call, save the project and execute the program.
Now we can see the output before slap a equals a hundred and B equals 200.
But after slap a equals 200 and B equals 100, it shows that the change has reflected outside the function
as the only kind of value that changes do not reflect outside the function.
Both the actual and formal parameters refer to the same locations.
So any changes made inside the functions are actually reflected in actual parameters of the color in
order not to prolong the time of decision.
We will finish sheet and we will continue the content in the next session.
Goodbye.