Hello and welcome to the gold and programming language course in the previous session, we talked about
Neal pointers and changing pointer value and indecision.
We want to talk about the other pointers concept.
Sending a variable to a function in GO.
Pointers in go programming language or go blank is a very bad, which is used to restore the memory
address of another variable.
You can also pass the pointers to the function.
Like to validate this?
There are two ways to do this as follows.
First copy that you.
In cop Emanuel Chase, which is the norm on a state, then you pass the value of a very able to a function.
Any change to the value of the variable has no effect on the variable sense because a copy of that variable
is sent to the function.
Now go to be school program to illustrate how to use copy value and passing it to the function.
First created function with integer type as parameter, for the example, print function,
fine print, a type of it ends as a parameter.
Now initialize eight point five hundred a equals five hundred.
Now go to create the main function, define the normal variable and initialize it, right?
X equals.
Now display value of variable before calling by function.
If if!
The value of x P4.
Function call is first the legislation and set the value it's.
Go to the next line in calling dysfunction, buy very evil print and set barricaded inside it as arguments
go to the next line and again display the value of the after call function.
If Earth
did value on the the after function, call this curse entity that can slash and and set the value to
fix, reformat the code, save the property and execute the program.
Now we can see the output before calling function, the value of X is 100.
And after calling function, the value of X is 100 hundred.
We see in the output that no change is made to the variable passed to the function.
Because in this case, a copy of the variable is sent to the function.
Now go to a site and continue.
Second reference value.
In this case, in fact, the address of the ivory bill is sent to a function.
And any change on the very bad inside the function, which is seen as a pointer, will cause a change
on the main value that now go to the school program to create a pointer and passing it to the function.
First, clear, the last quote.
Save the project and it's ready to write first.
Taking it function with integer tie pointer as a parameter for the example we call display function
and sit an integer pointer as parameter
FAJ display.
A and set a time for it has three means as a pointer now initialize it by five hundred Asterix A equals
five hundred, so we create the function y and endpoint or parameter and initialize it.
Now go to create the main function, go to main function, define the normal variable and initialize
it by, for example, a hundred.
That equals 100.
Now display value of that either before calling by function.
If if the value of the X before function card is first and the back is less and and set the variable,
it's
now calling the display function by passing pointer to function and we send address of value that is
as parameter, for example, display and set ampersand the X.
And go to the next line and again, this believe your variability after cutting by function, if f value
of X after function, Carney's personality that his left hand and set the value to X.
Reformat the court, save the project and execute the program.
Now we can see the output.
Value of XP before function call is a hundred and after calling function value off is 500 in the output,
we see that the value of the value was sent to the function has changed because the address of the variable
has been sent to the function and the change on it has caused a change in the main value of it in order
not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.