Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,540 --> 00:00:09,090
All righty, so in this video, what I would like us to do is simply to understand how we should create
2
00:00:09,090 --> 00:00:18,690
a constant in our C programming language now that we've been introduced with what basically the general
3
00:00:18,690 --> 00:00:20,060
idea behind concept.
4
00:00:20,550 --> 00:00:23,530
And now let us talk how they can be used in C.
5
00:00:24,090 --> 00:00:31,560
So there are a couple of definitions that you can use, but the default definition is simply by adding
6
00:00:31,560 --> 00:00:35,830
the word const before the variable declaration.
7
00:00:36,570 --> 00:00:42,990
So, for example, if we know that our year of birth should remain the same during the execution of
8
00:00:42,990 --> 00:00:49,260
the program, then it makes sense to create some variable and to define it as const right.
9
00:00:49,260 --> 00:00:55,520
Because we don't want this variable, this value that we will give to change over time.
10
00:00:55,530 --> 00:00:55,690
Right.
11
00:00:55,710 --> 00:01:00,930
Because the year of birth probably he doesn't make any sense that it will get changed.
12
00:01:02,430 --> 00:01:06,930
So in this case, what you would like to do is simply do the following.
13
00:01:06,960 --> 00:01:11,250
OK, so we use const int year equals to do thousand.
14
00:01:12,150 --> 00:01:17,690
So very, very simple to the way we created our standard variable.
15
00:01:17,880 --> 00:01:21,650
Just just like you, you've created your standard variable, just that.
16
00:01:21,670 --> 00:01:25,070
Now you simply add the keyword const before.
17
00:01:25,110 --> 00:01:28,110
OK, so const integer equals to two thousand.
18
00:01:28,770 --> 00:01:31,540
It doesn't have to be of an integer type.
19
00:01:31,610 --> 00:01:37,180
OK, these kind of values may also a constant valued may also be of a floating point.
20
00:01:37,200 --> 00:01:43,150
I for example like this const float salary equals to thirty one point thirty five.
21
00:01:43,620 --> 00:01:49,920
OK, that's also OK and basically very similar to how you create a variable.
22
00:01:49,980 --> 00:01:56,050
OK, we are talking now about the syntax of constants and see how we create these constants.
23
00:01:56,670 --> 00:02:06,390
So simply adding the cons, the word before and now any attempt that may be used to change this value
24
00:02:06,420 --> 00:02:09,660
will result in a compilation error.
25
00:02:10,930 --> 00:02:18,430
So basically, that's kind of OK, because these compilation error is kind of nice, because if you
26
00:02:18,430 --> 00:02:23,770
will attempt to change its value, it will not be like a problem during the execution.
27
00:02:24,100 --> 00:02:27,280
You will get notified at the compilation step.
28
00:02:27,460 --> 00:02:33,460
OK, so if you will attempt to I don't know if you have, like, I don't know, on a constant salary
29
00:02:33,460 --> 00:02:36,910
per hour, it does not suppose to get changed.
30
00:02:36,910 --> 00:02:39,840
Is also your year of birth.
31
00:02:39,850 --> 00:02:43,450
It's not supposed to get changed during the execution of your program.
32
00:02:43,720 --> 00:02:50,680
So if you simply would have tried to change this value during ah during some, I don't know, function
33
00:02:50,680 --> 00:02:53,200
or whatever calculation you've made by mistake.
34
00:02:53,200 --> 00:02:53,470
Right.
35
00:02:53,470 --> 00:02:56,010
You even you didn't even notice.
36
00:02:56,290 --> 00:03:03,580
So then the compiler will tell you, hey guy, listen, there is a problem, please check it out once
37
00:03:03,580 --> 00:03:06,610
again, the constant value that you are trying to change.
38
00:03:08,170 --> 00:03:10,450
So basically that's how it works.
39
00:03:11,830 --> 00:03:12,250
All right.
40
00:03:12,260 --> 00:03:19,420
So to summarize, you get only one chance to set its value of a constant at the initialization phase
41
00:03:19,420 --> 00:03:25,180
in this case, after words you are not allowed to modify during the execution of your program.
42
00:03:26,110 --> 00:03:32,380
And I hope that's clear because it's not so difficult topic in my opinion.
43
00:03:32,770 --> 00:03:40,180
But some people find it like hard to grasp, especially with information I'm going to share with you
44
00:03:40,330 --> 00:03:41,710
on my next video.
45
00:03:41,980 --> 00:03:45,550
So stay tuned and we will cover everything up really quickly.
46
00:03:45,850 --> 00:03:48,820
So, yeah, I think we are ready to move on.
47
00:03:49,240 --> 00:03:50,110
Thank you for watching.
48
00:03:50,140 --> 00:03:53,760
My name is what we sell for Tech and we are moving forward.
49
00:03:54,250 --> 00:03:58,060
Let me know, of course, if you have any questions and do them by my.
5014
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.