And.
Hello and welcome to the Guoliang Programming Languages course in this session.
We want to talk about the pointers concept.
Pointers and go like pointers in go programming language is a variable, which is used to restore the
memory address of another value, even pointers and go blank is answer turned as the especial value
is.
The variables are used to store some data at a particular memory address in the system, the memory
address is always found in hexadecimal format
pointers and go are easy and fun to learn.
Some go programming tasks are performed more easily with pointers, and other tasks such as command
by reference cannot be careful without using pointers, so it becomes necessary to learn pointers to
become a perfect go programmer.
As you know, everybody debate is a memory location, and every memory location has its address defined,
which can be accessed using Ampersand Operator, which denotes an address in memory.
Consider the following example which will print the address of the variable defined.
A pointer is a special kind of variable, which is not only used to restore the memory addresses of
other variables, but it also points where the memory is located and through lines of veins to find
out the value is stored at the memory location.
It is generally termed as a special kind of variable because it is almost declared as a variable.
But with asterisk or d referencing operator.
Declaration and initialization of pointers.
There are two important operators which we will use in pointers first.
Operator Answer turned as the D referencing operator used to declare a pointer of any event and access.
The value is stored in the address and second ampersand operator termed as address operator use to return
the address of a very bad or to access the address of a variable to a pointer.
The general form of the pointer variable declaration is that Vatanen and Estar that type here type is
the pointers based type.
It must be a valid C data type and that name is the name of the pointer value.
But the asterisk you used to declare a pointer is the same asterisk that you use for multiplication.
However, in this statement, the asterisk is being used to designate a variable as a pointer.
Following are the valid pointer declaration.
The actual data type of the value of all pointer is whether integer float or otherwise is the same along
hexadecimal number that represents a memory address.
The only difference between pointers of different data types is the data type of the variable or constant
that the pointer points to.
Now go to Waskow and illustrate how to declare and initialize pointers.
First, create a project folder for the example pointer and create a fine like me girl package main
and create main function for me.
First, define an actual variable declaration where a heat equals wind.
And second, define pointer a variable declaration for the example that name of it P and Typekit asterisk
it now is to address of a variable in pointer variable p equals ampersand, a value now display address
of a value that if their address are a
variable
percent X launches.
I guess this and and said the address of a variable ampersand, a go to the next line and display address
that is stored and put into a variable.
If their
address is talked in P
value, two
percent x lowercase back is less and and set the value of the P at the code and save the project for
access the value of pointer using the asterisk.
This is the inferencing a pointer using asterisk operator B4 a pointer a variable to access the value
is stored at the variable at which is pointing now.
Display value of pointer value even by the following code if the
value of estar p value of a
percent d backslash and and set the S time p now reformat the code, save the project and execute the
program on 1st.
Go to the project folder, see the pointers and run the project by Go Wrong.
I guess let's make that go now.
We can see the output first with the address of a variable by the hexadecimal format and then address
is stored and p variable by the hexadecimal.
And third, we see value of SRP variable that is 20, then the above code is compiled and executed.
It produces the following result.
First, we could define an actual variable named a then defined that point to a name p and s address
of a variable in point of about even after each display.
As a result, actual variable by ampersand symbol and display pointer address by accessing P variable
and display value of pointer by accessing asterisk symbol.
In order not to prolong the time of decision, we will finish it and we will continue the content in
the next session.
Goodbye.