So teachers can be quite dangerous.
So you do need to use them properly and really think about what you're doing.
Every every single time when you use one and the reasons why using one.
So you saw before that if you had a pointer but say this pointer and you set it to null pointer you
can't dereferences right
because it doesn't know it doesn't know what my pointer is at this point because no no pointer is not
a type.
This is not it it's not types doing something.
This is very bad.
OK.
So that's kind of one pitfall.
There are others though.
So let's see a different example so say we want to return a pointer so like this in which we just kind
of make it right here.
So we say it's just five
or turn the value of x and in let's just say it's pointer equals to phunk
and we're going to do that's value pointed to by X..
Winter is next winter.
You got.
And if try this.
So what's happening here.
Values one that's kind of strange.
So remember what I said about lifetime here.
So X will be destroyed at the end of the function.
So if you remember the lifetime lecture this only has a lifetime of this function so it's destroyed
as soon as it returns.
So therefore returning an address that has been destroyed doesn't shouldn't exist anymore.
At the end of this function.
So the moral of the story here is you should never return an address of a local variable out of its
function.
Of course it's the same if you use a reference.
So in a similar way you shouldn't do something like this.
We had a pointer here.
It's
changes to be it's X so what changes FOID
and you should do something like this.
Say it.
Why.
Ten inch x 2 that can do this and it's set.
Ch ch x 5 year an x K.
You X is.
So this
so the value of x is 5 even though we supposedly changed it right.
Well this is it is not quite the same.
This doesn't do what you think it does.
K because this pointer will be destroyed by the end of this function.
Similar to the last example.
So you're kind of giving it a an address that will be destroyed and itself will be destroyed at the
end of the function.
So it doesn't really change X at all here.
So we're seeing some more pitfalls that we might run into a bit later when we get into some more more
new stuff.