OK, so with that, let's go ahead and move on to the next thing, I think that's kind of enough on
that.
It's kind of a simple topic.
So now we move on to these assignment operators.
So this is kind of interesting.
We have this plus equal minus equal times equal and divided equal.
So this is really the same thing as doing something like.
Let's see what we have here, so we have one.
Let's go ahead and use that.
So if you wanted to say something like I one equals.
I one plus two.
Basically, this is you just wanting to update I one, right?
So I one right here is five.
So this is kind of the same thing as saying, OK, I one equals five plus two.
Actually, the same thing, except that you're maybe not sure what the value is that's inside of the
eye, one variable.
Maybe it's five.
Maybe it's something else.
And so an important thing is to not try and pretend that you know what it is, because that way you
can let it be multiple things we'll see later on that the user, often the user of the program, is
the one that will describe what type of numerical data you're getting.
So a good thing is just to see if you want to update one, you would just say, OK, I want i1 whatever
it is to be two more now than it was previously.
And that is something you can do by saying, All right, let's make I one have the value.
So assignment operator, whatever it is, plus two.
So now let's talk about this stuff.
So basically, what you can do is instead you i1 plus equals two, which is essentially the same thing,
so same as IE one equals.
So it's basically the same as this same thing as saying I one equals one plus two.
It's just a shorthand version of it.
So let's go ahead and verify that.
So I'm going to have this line right here.
I'll actually say I want equals five to reset it in between here.
So let me do a C out, and I'm going to say I won and C and line and then what I'm going to do is copy
this and then we'll put it right here and then we'll put it right here.
So we'll very well actually put it before this, too.
So we'll verify that it starts out as five.
Then we'll show that we add two to it and store it back into it, set into itself.
And then we will set it back to five.
And we'll do this this right here and show you that it has the same exact result as this one right here.
So let's go ahead and save this.
I'm going to compile it.
I'm going to run it.
And let's look at our output here.
All right.
So we have it's hard to get the outfit here.
All right.
So.
We printed this out still, so I'm going to comment this out.
Let's go ahead and compile this, and then again, I've actually got to save.
So I'm I run this again and you notice that.
We have what we kind of expect.
So it starts out as five, because that's what it originally was.
The variable was five of there.
Then we add two to it and store it back into itself.
So this becomes seven.
Then you is what we do is we reset it to five.
We print that out to confirm it, which is this five right here and then we do this i1 plus equals two,
which is the same thing as saying I want equals I one plus two.
We print it out just to confirm it has the same result.
So really, this is just a shorthand.
Version of this just makes it simpler, it's kind of nice cleaner.
And it's really the same for all the operators here, so I can actually do a multiplication.
And I'll do a multiplication here, and so this will be five times to rather than five plus two, right?
So let's go ahead and save this.
I'm going to compile it.
I'm going to run it and you notice that we get what we expect to.
So five, we multiply times.
Two.
We print out 10, because that's what it is.
Then we set it back to five.
We confirm that.
Then we go here and we do the same thing five times.
Two is 10 stories that back in I one printout, I won and I want us 10.
And it's going to be the same for all these other operators as well, just using the, you know, associated
basic operator.
Cool.
So pretty interesting.
Once again, I'm going to go ahead and kind of comment this out.
You can leave them if you want.
What's?
All right.
So now I'm going to talk about something kind of cool and interesting, which are the plus plus and
minus minus operators, I actually need to change this.
This is actually something called fixed, so we'll talk about that too.
So what I'm going to do now is, let's say I want to.
Just add one to a variable, so I want to increment it in my increment.
I just mean moving up by one.
So add one to something.
So it would be something like this.
I want equals I one plus one.
Something like that, or if I want to subtract one, it would be like I one equals one minus one.
And we already just talked about the fact that this can be simplified, right?
It's going to be simplified to A1 plus equals one.
And this basically can be simplified to A1 one minus equals one.
Right?
So something even simpler if we're dealing with just one wanting to add or subtract one from a variable,
we can actually do something like plus plus I i1 and minus minus A1.
So those essentially do the same thing.
So I can say A1 five to reset it here.
I will say one five.
I one equals five.
So let's go ahead and just print this out to show that it's the same thing.
So I do sneak out.
I won
and.
I'll go ahead and just put it here, we know that we're resetting it to five, right?
So I'm not going to like show that this time.
But now we print it out and we should see that on the bottom to should correspond with the top two.
So I save it.
I compile it, I run it.
And it does.
You notice we have a fix to start out with.
So I won was five.
And then what we did was we added one to it.
So we said i1 equals one plus one.
And, you know, this is also the shorthand we could have just used that as well because I just talk
to you about that.
So I printed that out.
It was six.
We reset to five.
We did a little minus and that was four.
Right.
So we said to five minus one was four.
Then we we said to five and we did a plus.
Plus you notice that increment did it to six and then we reset to five.
We did a little minus minus in that decommitted from five to four.
So they really do the same thing as long as it's one plus plus increment by one minus minus decrements
by one.
Cool.
So I think that's also pretty straightforward as well, except for this little part about it, which
is something I'm going to go over right now, so I'm going to go ahead and works.
Can't say, OK, can't seem to delete this highlight.
OK, so I'm going to go ahead and just delete this stuff.
I don't necessarily need that right now.
Let's talk about this something called prefix and postfix, so you have a fusion example like this.
So I'm going to make a new engineering and call this and and I'm going to call this like I to.
And I say, and I two people say one, and then what I'm going to do is I'm going to say and I three
equals
plus plus I want.
All right.
And then what I'm going to do is just say and to oops, sorry.
And know I already have it too.
So I'm going to say I two equals or no, I for some say and I four equals I two plus plus.
So you probably are thinking, well, these are like similar things, what you do is you set a two to
buy one, so I one has five, then I two is going to have five, right?
And then what you do is you make a new integer called a three.
And then you do a plus plus I one well, I know what that does, right, it adds one to one which has
five, so five plus one is six.
It's going to store six in here.
So I for here.
Yeah, it's pretty much same thing, right?
It's adding one to I two, which is going to be six and it's going to store that and I four.
So let's go ahead and check out what happens here.
So I'm going to go ahead and print out.
I'm actually going to say kind of like our hello world, you know, in quotes, I'm going to put a little
phrase here, but I'm just going to use it to label what we're printing out.
So I'm going to say I won and then I'm going to actually print out.
I want value and then I'm going to put a little column in a space and I'm going to say I three and then
I am going to print out I 3's value and then I'm going to put the my.
And then I'm going to do the same thing down here, but I'm going to change this to try to pronounce
it its value.
And then I'm going to change this to four.
You print out my force value.
So let's see what happens here.
Save it.
Compile it.
Run it.
OK.
All looks pretty good, except for, whoa, what is it that we kind of might have expected this stuff?
So we did take five and copy it into here because I one was five.
Let's see what happened here, so we added one two.
I won, so I won was five.
We added one to it.
So five is now six.
I want us now six, right?
So we changed.
I won two six and that's what I printed out.
So that kind of makes sense.
We did the plus plus and I wanted to actually change that as well, though.
So the variable that has the plus plus associated with it also gets changed is not just the thing that
we save it into.
So both of these have six now we added one to one that is six, and we took that result, which is six
and stored it in three.
So that's why and when we print this out, we see them both at six.
This one, however, it added one to it too.
So I two was five, right?
Because we stored five and I two.
So five now became six.
But it didn't stop six an eye for eye forces, five.
So what's actually happening here is something really weird.
What it's doing is it's just evaluating this first.
It's actually saying, Oh, I four equals I two, what is I two?
Well, I choose five.
OK, cool store five and a four.
And then afterwards it's doing a two plus plus, so it's turning five into six.
But it just already stored five and I four.
So it's not restoring six, it's just storing five and I have four.
So that's why it prints out.
I four is, which is five.
It only has five.
But I two got incremented to six after the storage part happened.
The assignment after the assignment happened, so five got stored in the.
Then afterwards, it's just leaves my four alone and it then increments I to.
So pretty interesting concept here.
This is called prefix versus postfix, so this would be prefix.
This would be postfix.
You can think of pre and post like before and after.
So this style makes the incremental version happen before this style makes the incremental version happen
after so.
Pretty, pretty weird, pretty weird, but just something to keep in mind, also something to keep in
mind is the fact that this plus plus changes the value of this variable as well.
It's not just only storing a result in here, like let's go ahead and change this to high one plus equals
one.
And see what happens here.
I won't put this even in parentheses here.
Let's see what C++ does.
See if he yells at us.
No, it doesn't.
OK.
So you notice that it actually does the same thing here.
If we do this, so if we do the plus equals one, it's actually doing that.
But if I was to just do this, let's go ahead and say this.
So I say this, compile it.
Now you notice that I want to still five, so this had an equals on it, so it actually assigned it.
But before we were just using a like a plus plus I right now, we do one plus one.
It's not actually changing.
I one to A1 plus one, it's just taking the result and storing it inside this i3, unlike the plus plus
i1, where in this case, it actually modifies both.
So it modifies the i1 by increment it by one, and then it takes that result in stores in here.
So both variables get changed.
Similar thing with minus minus.
I can change this to minus minus.
And we're going to see a similar style of result.
So you notice that these two are the same when we do the pre and communication.
But when we do the posting fermentation, we notice that it does the same thing where it stores it to
its original value and 04, and then it just changes it to with the minus minus.
So that's why you see A4 here has five.
Yet the two got decommitted from five to four.
OK, so this is probably kind of a lot again, you know, each one of these kind of beginning of the
course lectures is stuffing a lot of information into your brains.
What you should really do is practice all of this as much as you can.
So use all of it together.
Go ahead and use all the standard operators.
Combine them with the parentheses.
Make the biggest mathematical expressions.
You can save those and other variables.
Update them with the plus equal minus equal times equal.
Print them out and then also mess around with the prefix and postfix here with the incremental option.
OK, so hopefully that was enough to explain these concepts for you.
Like I said, get as much practice as you can.
We don't have actual assignments yet because we kind of need to learn some more tools, learn about
some more tools to be able to solve some actual problems.
So right now, it's all about practice makes perfect.
All right.
So practice everything that you've learned so far, which is making variables messing around with them
with operators, both logical, right, which we learn before and arithmetic now that, you know, medic
print stuff out.
So it's always like variables, mess, mess around with variables so, you know, changing them and
changing them, making new variables, modifying them, printing those variables out, printing those
variables out in expressions like this.
And, you know, just kind of repetition and getting that stuff down, because very soon, in fact,
in the next few lectures, we're going to move on past just having these basic primitive types and variables,
and we're going to look at some much bigger concepts.
All right.
So with that, I will see you in the next lecture.