Press "Enter" to skip to content

Pointers – Go Lang Practical Programming Tutorial p.4


what is going on everybody welcome to

what is going on everybody welcome to part 4 of the go tutorial series in this

part 4 of the go tutorial series in this

part 4 of the go tutorial series in this part what we’re really talking about is

part what we’re really talking about is

part what we’re really talking about is pointers which is pretty much the last

pointers which is pretty much the last

pointers which is pretty much the last element that’s going to be necessary for

element that’s going to be necessary for

element that’s going to be necessary for you to understand the basic kind of go

you to understand the basic kind of go

you to understand the basic kind of go web server example so also if you’re

web server example so also if you’re

web server example so also if you’re like coming from something like Python

like coming from something like Python

like coming from something like Python this is totally foreign to you so so

this is totally foreign to you so so

this is totally foreign to you so so it’s probably a good idea we cover it so

it’s probably a good idea we cover it so

it’s probably a good idea we cover it so the first thing I’m gonna go ahead and

the first thing I’m gonna go ahead and

the first thing I’m gonna go ahead and do is kind of clean up what we’ve got

do is kind of clean up what we’ve got

do is kind of clean up what we’ve got going on here so first of all we’re just

going on here so first of all we’re just

going on here so first of all we’re just gonna be using format so I’ll get rid of

gonna be using format so I’ll get rid of

gonna be using format so I’ll get rid of the parentheses there we’ll clean up

the parentheses there we’ll clean up

the parentheses there we’ll clean up these two functions and I’ll just empty

these two functions and I’ll just empty

these two functions and I’ll just empty out main because we don’t need anything

out main because we don’t need anything

out main because we don’t need anything there

there

there alright so let’s say we have a variable

alright so let’s say we have a variable

alright so let’s say we have a variable and we’re gonna say it’s X colon equals

and we’re gonna say it’s X colon equals

and we’re gonna say it’s X colon equals and we’ll say that if X is equal to 15

and we’ll say that if X is equal to 15

and we’ll say that if X is equal to 15 what type is 15 you should know now now

what type is 15 you should know now now

what type is 15 you should know now now what we can say is a colon equals and

what we can say is a colon equals and

what we can say is a colon equals and that’s going to point to X so the way

that’s going to point to X so the way

that’s going to point to X so the way that we point to something is with the

that we point to something is with the

that we point to something is with the ampersand and then the variable we want

ampersand and then the variable we want

ampersand and then the variable we want to point to so this is gonna wind up

to point to so this is gonna wind up

to point to so this is gonna wind up being the memory address I’ll just write

being the memory address I’ll just write

being the memory address I’ll just write that out and then now let’s go ahead and

that out and then now let’s go ahead and

that out and then now let’s go ahead and format dot print line a just so we can

format dot print line a just so we can

format dot print line a just so we can see what we’re doing so let me bring up

see what we’re doing so let me bring up

see what we’re doing so let me bring up a command line and go run go go boom so

a command line and go run go go boom so

a command line and go run go go boom so that’s actual memory address where the

that’s actual memory address where the

that’s actual memory address where the value for X’s is being stored so now

value for X’s is being stored so now

value for X’s is being stored so now what we can do is like what if we so so

what we can do is like what if we so so

what we can do is like what if we so so basically you if you want to point to

basically you if you want to point to

basically you if you want to point to something use the ampersand but if you

something use the ampersand but if you

something use the ampersand but if you want to read through a memory address

want to read through a memory address

want to read through a memory address you use the asterisk or star so so what

you use the asterisk or star so so what

you use the asterisk or star so so what we could say is format dot print line

we could say is format dot print line

we could say is format dot print line asterisk a save that run that and you

asterisk a save that run that and you

asterisk a save that run that and you see in this case you get 15 because

see in this case you get 15 because

see in this case you get 15 because that’s that’s currently what the value

that’s that’s currently what the value

that’s that’s currently what the value of x is now what if we said asterisk a

of x is now what if we said asterisk a

of x is now what if we said asterisk a equals 5 what what do you think we’ll

equals 5 what what do you think we’ll

equals 5 what what do you think we’ll wind up happening there so let’s go

wind up happening there so let’s go

wind up happening there so let’s go ahead and save that run that whoops we

ahead and save that run that whoops we

ahead and save that run that whoops we didn’t

didn’t

didn’t anything else let’s go ahead and print X

anything else let’s go ahead and print X

anything else let’s go ahead and print X now so format dot for its line X so now

now so format dot for its line X so now

now so format dot for its line X so now X is actually equal to five because it’s

X is actually equal to five because it’s

X is actually equal to five because it’s changed so so now like just just for fun

changed so so now like just just for fun

changed so so now like just just for fun a the reading through of that memory

a the reading through of that memory

a the reading through of that memory address of X so the reading through of

address of X so the reading through of

address of X so the reading through of whatever’s at a equals whatever’s

whatever’s at a equals whatever’s

whatever’s at a equals whatever’s through at a times every through day

through at a times every through day

through at a times every through day that looks fun so what’s gonna be the

that looks fun so what’s gonna be the

that looks fun so what’s gonna be the output there right you should be able to

output there right you should be able to

output there right you should be able to visually look at this and know what’s

visually look at this and know what’s

visually look at this and know what’s what’s gonna say but oh we still need to

what’s gonna say but oh we still need to

what’s gonna say but oh we still need to print it out huh

print it out huh

print it out huh let’s print let’s do format dot print

let’s print let’s do format dot print

let’s print let’s do format dot print line X what happened hey there we go

line X what happened hey there we go

line X what happened hey there we go we’re Matt dot print line X and then

we’re Matt dot print line X and then

we’re Matt dot print line X and then also let’s let’s print out asterisk a

and that’s probably so we’ll save that

and that’s probably so we’ll save that we’ll run that and as you can you

we’ll run that and as you can you

we’ll run that and as you can you probably could have guessed it was going

probably could have guessed it was going

probably could have guessed it was going to be five times five

to be five times five

to be five times five but anyways pretty cool it’s it’s super

but anyways pretty cool it’s it’s super

but anyways pretty cool it’s it’s super simple once you get used to it but it as

simple once you get used to it but it as

simple once you get used to it but it as a foreign concept it gets kind of

a foreign concept it gets kind of

a foreign concept it gets kind of challenging just know that anytime

challenging just know that anytime

challenging just know that anytime you’ve got ampersand that’s the memory

you’ve got ampersand that’s the memory

you’ve got ampersand that’s the memory address that’s leading to whatever

address that’s leading to whatever

address that’s leading to whatever variable you pass and then if you want

variable you pass and then if you want

variable you pass and then if you want to read what’s at that variable or

to read what’s at that variable or

to read what’s at that variable or what’s at that memory address rather

what’s at that memory address rather

what’s at that memory address rather you’re gonna use the asterisk alright so

you’re gonna use the asterisk alright so

you’re gonna use the asterisk alright so that’s all for pointers and in the next

that’s all for pointers and in the next

that’s all for pointers and in the next tutorial we’ll actually start with our

tutorial we’ll actually start with our

tutorial we’ll actually start with our super basic web server example if you

super basic web server example if you

super basic web server example if you have questions comments concerns

have questions comments concerns

have questions comments concerns whatever you can feel free to leave them

whatever you can feel free to leave them

whatever you can feel free to leave them below otherwise I will see you in the

below otherwise I will see you in the

below otherwise I will see you in the next tutorial

”

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *