WEBVTT

00:00.830 --> 00:06.950
I said before that variables are locations in memory of certain size because of that type and those

00:06.950 --> 00:12.960
variables can change using the assignment operator or addition or other operators.

00:13.370 --> 00:19.610
But a lot of the time we want something that's just completely constant all the time and we never want

00:19.610 --> 00:21.630
it to change.

00:21.680 --> 00:25.090
So let's see how we can do this.

00:25.130 --> 00:30.090
So there's something in C++ called the conc keyword.

00:30.170 --> 00:34.380
And let's make a conc constant for pi.

00:35.050 --> 00:35.770
Hi.

00:35.800 --> 00:42.430
So we say Konst float Pi three point 1 4 1 5 9.

00:42.470 --> 00:45.280
Say OK.

00:45.630 --> 00:53.560
And so our convention for constants naming the constants will always be uppercase letters and if we

00:53.560 --> 00:57.820
have multiple words we'll use underscores.

00:57.820 --> 01:09.230
So let's say two pi would be two times this say.

01:09.540 --> 01:16.350
For now we're CAN going to use pi so see a complete example with this.

01:16.540 --> 01:23.610
So let's say float radius in c c h.

01:25.740 --> 01:32.100
These enter the radius of a circle

01:37.160 --> 01:42.060
in radius C..

01:47.130 --> 01:53.190
Come brunette's the circle is

01:56.370 --> 02:00.900
two times pi times the radius

02:07.500 --> 02:07.860
k.

02:07.980 --> 02:09.270
So run this

02:11.750 --> 02:14.260
say 10.

02:14.430 --> 02:19.030
So the circumference is 62 point three you on it.

02:19.470 --> 02:29.350
So notice how we can use pi after you'd find it in other places in say error arithmetic operations.

02:29.460 --> 02:31.820
And I said before that it's constant.

02:31.820 --> 02:38.770
So let's try to actually change PI rate here and see what happens.

02:38.780 --> 02:49.760
So we actually got an error so it says hey you can't just add 1 to pi because it's constant to read

02:49.760 --> 02:55.360
only variable and not assignable as it says in gcc.

02:55.430 --> 02:57.940
So it really is conc and we can't change it.

03:00.830 --> 03:04.400
So you may ask why would we ever need constants.

03:04.400 --> 03:10.580
Why can't we just put three point 1 4 1 5 here instead.

03:11.030 --> 03:18.710
Well say if we use pi in many places in the code but for some reason we had to change it to make it

03:18.890 --> 03:25.930
more or less precise let's say we would only need to change it here in this one place.

03:26.120 --> 03:31.130
And then all the other places that use pi would get that change.

03:31.160 --> 03:36.170
So that's one reason why we always want to use constants.

03:36.170 --> 03:44.690
If they apply to our situation I never want to see what's called Magic Numbers which is just say we

03:44.690 --> 03:52.880
had instead of Pi we had three point 1 4 here and this is this three point four is really just a magic

03:52.880 --> 03:53.240
number.

03:53.240 --> 04:01.550
We don't really know what it is or what it represents and really constants are a good way to make code

04:01.610 --> 04:04.000
more readable and understandable.

04:04.280 --> 04:05.750
So that's why we use it.

04:05.930 --> 04:11.600
So we're always going to use constants where appropriate unless something like zero we don't need a

04:11.600 --> 04:17.150
constant effort for this for example doesn't that doesn't really matter too much.

04:17.240 --> 04:27.210
So we'll be using the concepts he word in actually in a few different ways in the next sections.
