WEBVTT

00:00.730 --> 00:08.300
In this lecture we'll go over medic operations that you can do these will really be like grade school

00:08.300 --> 00:10.540
math that you've done.

00:11.090 --> 00:24.380
So what starch won't say we have a variable x and we'll sign it five in one of it y and will sign it

00:24.470 --> 00:36.900
11 Let's make another one say Zed and we'll say X plus Wise's the addition operator so we'll see what

00:36.900 --> 00:38.160
this output it's

00:41.010 --> 00:43.870
you said is

00:52.050 --> 00:55.570
No it's right.

00:55.720 --> 00:59.700
And it gives you 16 as you probably expect.

00:59.740 --> 01:07.270
So it's so shy a minus.

01:07.490 --> 01:13.520
He's negative 6 and multiply that should give you five.

01:13.520 --> 01:14.450
Right.

01:15.080 --> 01:23.040
So these are what are called a binary operator binary meaning there's two sides to this operators.

01:23.060 --> 01:28.550
You have the operator in the middle and then you have on the left side of this X and then on the right

01:28.550 --> 01:30.130
side the Y.

01:30.140 --> 01:33.990
That's why it's binary because it works on two different sides of itself.

01:35.640 --> 01:41.840
But let's see what happens if you say divide things get a bit more interesting.

01:43.050 --> 01:46.870
It's from that and the value is zero.

01:47.720 --> 01:57.710
Rants are saying 5 which is the value X and 11 which is the value y and 0.

01:57.840 --> 01:59.210
And why is that while.

01:59.250 --> 02:08.660
Like I said in The Last Lecture types are interpreted in a specific way and integers are whole numbers.

02:08.720 --> 02:19.820
So you can't have something like zero point five or something like this for like that it'll always lop

02:19.820 --> 02:24.710
off the end of it which should be its decimal point onwards.

02:24.740 --> 02:29.400
And just use the whole number which would be zero in this case.

02:29.450 --> 02:31.940
So you have to be very careful about that.

02:31.970 --> 02:38.030
In fact you can actually take advantage of it in certain situations which we'll probably see later on.

02:39.200 --> 02:45.710
So let's use a different operator called the modulus operator.

02:45.710 --> 02:47.550
This is the percent sign.

02:49.140 --> 02:56.820
So if you remember back in your grade for five or three math class you probably went over something

02:56.820 --> 03:04.390
like long division and if you remember if something didn't evenly divide you always get a remainder.

03:04.790 --> 03:07.360
And this is what this is.

03:07.370 --> 03:21.170
So if you had say 11 as X into Y What do you think the value would be.

03:21.230 --> 03:23.060
What is the Zenn value here.

03:24.530 --> 03:35.680
Well it's one because you will divide 11 five times but there will be one remainer rate and that's what

03:35.860 --> 03:40.840
that's what this one is the remainder of the division that was was done

03:44.580 --> 03:53.080
and modulus is very useful for certain things and be using it quite a bit more later on in our programs.

03:53.430 --> 04:00.480
Is also very nice shortcuts to some of the operations that we can do.

04:01.720 --> 04:15.850
So say you wanted to we had X equals one and we said it's said as.

04:15.890 --> 04:22.600
For now let's say we had wanted to say X equals x

04:25.540 --> 04:31.340
plus 1 plus one can.

04:31.390 --> 04:37.090
So we're saying X gets value x plus 1.

04:37.100 --> 04:40.390
So at the end of this this should be two right.

04:41.060 --> 04:45.160
And we should have four as our result for zed

04:51.580 --> 04:52.810
for here.

04:53.100 --> 05:05.790
Well there's this shorthand that you can do it x plus plus this will be the same same results as above.

05:07.170 --> 05:08.530
Let's just comment that out

05:11.410 --> 05:14.040
and you should see again values for.

05:14.050 --> 05:15.490
So what is this.

05:15.540 --> 05:23.460
This line here this line 20 x plus plus is the exact same as this line above.

05:23.470 --> 05:30.900
In fact it's just a nice shorthand for this is what's called incrementing something.

05:31.300 --> 05:34.810
And you can actually do the same with decrementing as well.

05:34.960 --> 05:44.890
So you can actually say X minus minus will be the equivalent of X equals X minus 1.

05:45.030 --> 05:50.110
See that she's just 2 so X would be 0 at this point.

05:51.020 --> 05:57.090
At the end of 20 line 20 and 0 plus due to

06:00.770 --> 06:08.180
there's also other shorthands that are kind of interesting which are these show you do you do something

06:08.180 --> 06:09.160
like this as well.

06:09.180 --> 06:12.190
X plus equals 1.

06:12.260 --> 06:16.680
This will be the same as X plus plus with the same

06:21.470 --> 06:22.540
same ones.

06:22.750 --> 06:30.480
You also have X minus equals 1 which would be the same as X minus minus even use multiplying.

06:30.500 --> 06:37.190
So X times equals 2 which would multiply it by 2 and reassign the value.

06:37.430 --> 06:42.330
And you can do even to divide and modulus as well.

06:42.370 --> 06:49.220
So that's something interesting to keep in mind just for these are just shorthands programmers very

06:49.220 --> 06:54.700
much like shorthands because we don't want to type code all the time.

06:56.210 --> 07:01.980
So these are the basic operations that will work for.

07:02.140 --> 07:05.340
Double float and so on.

07:07.480 --> 07:11.200
But for char's This also works.

07:11.200 --> 07:14.260
So let's say we had to delete all this

07:17.030 --> 07:30.920
and say we can't share C equals a and we said C plus plus K.

07:31.130 --> 07:36.310
What do you think the value of c is.

07:36.330 --> 07:40.650
If we run it it's B.

07:40.950 --> 07:47.880
Capital B so you can actually add 1 to.

07:48.020 --> 07:51.950
This is actually this is a single coded a.

07:51.980 --> 08:01.730
Here is actually a number and that number corresponds with the what's called an ASCII table.

08:01.730 --> 08:13.220
So the ASCII table will have all of the letters and numbers for the ASCII set character set and this

08:13.220 --> 08:16.350
corresponds to a specific number.

08:16.490 --> 08:20.360
So A is 70 something I can't remember really.

08:20.480 --> 08:27.560
So one thing you should do after this lecture you shouldn't look up all the Ask the ASCII table and

08:27.920 --> 08:31.330
check to see what value a has.

08:31.330 --> 08:41.520
So in this case you should print out since we're adding 1 to a and then incrementing it at c or so.

08:41.870 --> 08:49.780
Remember Like I said it's all interpreted differently even though it could be used similarly.

08:49.780 --> 08:54.480
So we're using the binary operator addition here.

08:55.020 --> 09:03.630
And this is what's called a unitary operator because it only acts on one side as plussed class a unique

09:03.720 --> 09:06.890
OPERATOR So one unit.

09:07.050 --> 09:09.590
You mean in French

09:16.480 --> 09:24.870
so the last thing I want to talk about with arithmetic operations is what's called precedence.

09:25.270 --> 09:32.500
So let's say we had our original example here

09:36.030 --> 09:40.830
sequels five why sloven

09:43.100 --> 09:50.130
in said Kuhn's X plus Y.

09:50.530 --> 09:55.340
So this.

09:56.520 --> 10:01.180
So you'll notice here what happens first.

10:02.380 --> 10:10.810
Because you have two different Opper operators we have the addition operator and we have the assignment

10:10.840 --> 10:13.060
operator as well.

10:13.060 --> 10:17.480
And yet we know the results is 16.

10:17.500 --> 10:29.970
So we know it does this X plus wife first and then it assigns it that value 16 to Zed Well like I said

10:29.970 --> 10:40.320
this is called precedence and this this is something that all operators have in precedence is really

10:41.220 --> 10:47.340
you can think of it as kind of the order of operations that will happen first.

10:47.570 --> 10:56.030
So in this case this addition has higher precedence than the assignment because that's what was completed

10:56.030 --> 10:56.900
first.

10:58.390 --> 11:00.900
Here's another example.

11:00.970 --> 11:16.600
So let's say we had Zed equals 10 watts 30 times every 6 or 6 minus 9

11:20.970 --> 11:22.980
and this

11:27.220 --> 11:29.610
sace what's the end result.

11:29.620 --> 11:32.260
It's 181 k.

11:32.330 --> 11:37.250
So what happens first well if you remember you're old.

11:37.390 --> 11:46.030
Matthew probably learned something something effective bed mass which is multiplication and division

11:46.600 --> 11:51.010
will come before subtraction and addition.

11:51.070 --> 12:02.630
So this happens first this 36 times or 30 times 36 and then it gets divided and then you add then subtract.

12:02.630 --> 12:03.110
Right.

12:05.120 --> 12:11.660
So if you look up the there's also besides the ASCII table is also something called precedence table

12:12.740 --> 12:20.800
and you'll see in the precedence table that multiply and divide are at the same level but multiply will

12:20.800 --> 12:27.790
come first and it's higher precedence than addition or subtraction.

12:27.790 --> 12:34.480
Now if you don't remember any of this stuff which I I rarely don't want to remember what you should

12:34.480 --> 12:41.600
do is have parentheses around every so if you wanted this to happen first

12:46.720 --> 12:49.890
you'll still see 181 as the result.

12:50.050 --> 12:56.590
If say you wanted a different precedence Let's say you want to do the dition first

13:00.260 --> 13:05.210
10 plus 30 times 36 minus 9

13:10.110 --> 13:13.410
that give you a totally different number 8.

13:13.420 --> 13:23.810
So if you if you don't want any kind of ambiguity you really want to use your make clear use of parentheses

13:23.840 --> 13:25.950
to say what should come first.

13:25.970 --> 13:27.320
This will always happen first.

13:27.320 --> 13:36.810
This 10 plus 30 then it will multiply by 36 and divide and will subtract.

13:36.810 --> 13:45.850
So this is very very important stuff so always just remember if you don't want any ambiguity use use

13:45.880 --> 13:47.180
these parentheses.

13:47.350 --> 13:53.150
And after the lecture you should go and look up the both the ASCII table and the precedence table.

13:53.160 --> 13:58.140
See all of the operations that come for what.

13:58.200 --> 14:02.610
So in the next lecture we'll start talking about some simple input.
