Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,300 --> 00:00:01,700
What is going on, guys?
2
00:00:01,710 --> 00:00:06,330
And welcome back to another challenge in our AC programming course.
3
00:00:06,470 --> 00:00:09,220
And in this challenge, it's kind of a unique challenge.
4
00:00:09,240 --> 00:00:11,190
We are going to do something new.
5
00:00:11,670 --> 00:00:14,070
We are going to get this piece of code.
6
00:00:14,220 --> 00:00:20,940
And your task is without using the computer, just with a pen and a piece of paper, let's say your
7
00:00:20,940 --> 00:00:27,960
task is to think of what and what would and what should be printed in each of these printer lines.
8
00:00:28,620 --> 00:00:31,320
So we have here a couple of print of lines.
9
00:00:31,560 --> 00:00:33,450
So you can see it right here.
10
00:00:33,480 --> 00:00:42,660
One, two, three, four, five, six, six printer lines that print the values of two two variables.
11
00:00:42,690 --> 00:00:43,830
Number one, number two.
12
00:00:43,830 --> 00:00:52,890
And also the Pointer SPDR and BTR be in your task is to find out and write down on a piece of paper.
13
00:00:53,130 --> 00:00:58,620
What would be printed to the screen just based on your look of this code?
14
00:00:58,800 --> 00:01:04,350
This will help us understand where we stand with the material and make sure that we understand all the
15
00:01:04,350 --> 00:01:06,180
principles we've learned so far.
16
00:01:06,330 --> 00:01:07,500
So give it a try.
17
00:01:07,520 --> 00:01:12,570
Pause the video and resume in three, two, one.
18
00:01:13,050 --> 00:01:20,340
OK, so now you should be after you've written down all the answers on a piece of paper and you are
19
00:01:20,340 --> 00:01:25,050
ready to move on and to make sure that your results are actually good.
20
00:01:25,590 --> 00:01:33,510
So one of the ways to start this exercise, let's just I think let's go briefly to on what happens happening
21
00:01:33,510 --> 00:01:33,810
here.
22
00:01:34,350 --> 00:01:36,630
So we create we initially two variables.
23
00:01:36,660 --> 00:01:37,890
Number one and number two.
24
00:01:37,940 --> 00:01:39,090
And then one will be five.
25
00:01:39,120 --> 00:01:40,290
Number two will be seven.
26
00:01:40,320 --> 00:01:44,310
Just simple standard variables of an integer type.
27
00:01:44,460 --> 00:01:47,340
And then we create two pointer variables.
28
00:01:47,340 --> 00:01:48,660
Pointer is to end.
29
00:01:49,110 --> 00:01:52,160
And these two boxes, BTR, Way and Yerby.
30
00:01:52,620 --> 00:01:54,960
Currently they do not point anywhere.
31
00:01:54,960 --> 00:01:55,350
Right.
32
00:01:55,500 --> 00:01:57,750
They are on initialised.
33
00:01:58,170 --> 00:02:00,540
So these printer line is very simple.
34
00:02:00,810 --> 00:02:04,410
We print the value of number one and number two, and that's it.
35
00:02:04,470 --> 00:02:07,830
This will be our number one equals two five.
36
00:02:07,920 --> 00:02:10,200
And number two equals two seven.
37
00:02:10,350 --> 00:02:13,590
And now what we are doing is simply to point.
38
00:02:13,650 --> 00:02:13,900
OK.
39
00:02:13,950 --> 00:02:20,040
So we take the address of number one and put it inside of the BTR, a variable.
40
00:02:20,070 --> 00:02:23,650
So BTR A will now hold of the address of.
41
00:02:23,790 --> 00:02:27,270
Now one, the address of where number one resides.
42
00:02:27,420 --> 00:02:31,260
And we are doing also the same for BTR, Yerby and number two.
43
00:02:31,470 --> 00:02:33,420
So BTR and BTR.
44
00:02:33,420 --> 00:02:43,290
B, basically if we would have watched from from outside BTR and BTR B point to these two variables,
45
00:02:43,360 --> 00:02:46,310
they hold these two variables BTR and BTR.
46
00:02:46,320 --> 00:02:50,550
B hold the address of number one and number two.
47
00:02:50,730 --> 00:02:55,250
So that's very important to understand that these two variables hold addresses.
48
00:02:55,300 --> 00:03:01,890
They point to number one and number two, and you can access and change and do whatever you like to
49
00:03:01,890 --> 00:03:05,760
number one and two through the SPDR Array and Peter Yerby.
50
00:03:05,880 --> 00:03:08,780
So now here are the second print off-line.
51
00:03:08,790 --> 00:03:11,100
We see that we print exactly the same.
52
00:03:11,520 --> 00:03:16,440
And we know that PDR eight points to this variable and BTR B to the second one.
53
00:03:16,800 --> 00:03:19,200
And that basically doesn't change anything.
54
00:03:19,950 --> 00:03:25,050
Even if someone is pointing at another variable, that shouldn't change anything.
55
00:03:25,110 --> 00:03:29,490
So the result will be five and seven once again.
56
00:03:30,180 --> 00:03:32,550
And now what we are doing is kind of interesting.
57
00:03:33,240 --> 00:03:37,690
We know that if BTR a codes are the address of number one.
58
00:03:37,730 --> 00:03:46,350
And if you specify a pointer before you just saying that, go to the address that BTR a points to go,
59
00:03:46,350 --> 00:03:48,330
go there, go to number one.
60
00:03:48,360 --> 00:03:52,260
So it's simply almost the same as we would have written.
61
00:03:52,320 --> 00:03:53,970
Now one equals two.
62
00:03:54,270 --> 00:03:54,750
This one.
63
00:03:55,050 --> 00:04:00,480
So pointer BTR A will be equal to points or BTR A plus one.
64
00:04:00,540 --> 00:04:03,840
So this is equivalent to number one.
65
00:04:03,870 --> 00:04:08,390
You just access the other variable, number one, adjusting directly.
66
00:04:08,610 --> 00:04:11,430
So previously no one was five.
67
00:04:11,610 --> 00:04:13,590
So five plus one is six.
68
00:04:13,620 --> 00:04:17,400
And you just change the value inside of NUM one.
69
00:04:17,430 --> 00:04:19,680
So we know that right now.
70
00:04:19,710 --> 00:04:22,950
Now one behind the scenes equals the six.
71
00:04:23,490 --> 00:04:26,090
And also the same we do for NUM two.
72
00:04:26,400 --> 00:04:33,570
So BTR Appointer, BTR B equals 2.0, BTR B which is now two plus three and NUM two was seven.
73
00:04:33,590 --> 00:04:36,590
So we are going to get num two equals to ten.
74
00:04:37,300 --> 00:04:43,500
And now what we are going to print is the values of NUM one and number two and make sure that you really
75
00:04:44,070 --> 00:04:49,250
were were able to change the values of NUM one and two through.
76
00:04:49,320 --> 00:04:51,390
These are pointers.
77
00:04:51,690 --> 00:04:55,500
And the result is going to be six and 10.
78
00:04:55,560 --> 00:04:58,290
So have you done everything correctly so far?
79
00:04:58,620 --> 00:04:59,790
Please let me know if.
80
00:04:59,850 --> 00:05:00,410
Phew.
81
00:05:00,660 --> 00:05:03,060
I struggle with this topic.
82
00:05:03,450 --> 00:05:12,000
And if you got any stakes here, because I think that that only these two lines are new so far to what
83
00:05:12,000 --> 00:05:12,900
we've done here.
84
00:05:13,350 --> 00:05:20,760
And I think they're pretty much OK because we understand that we can access any of the elements that
85
00:05:20,760 --> 00:05:24,120
we point to and modify them in directly.
86
00:05:24,720 --> 00:05:31,770
And now what we are doing in lines 21, 22, we simply take BTR three, which holds the address of number
87
00:05:31,770 --> 00:05:34,020
one, and BTR beholds jetways of None two.
88
00:05:34,290 --> 00:05:42,440
And we say that BTR A will now hold the address are specified in BTR B, which is the address of Nahm
89
00:05:42,440 --> 00:05:42,840
two.
90
00:05:43,140 --> 00:05:50,310
So basically what's what's happening behind the scenes is that now BTR, a will point will point to
91
00:05:50,310 --> 00:05:50,920
number two.
92
00:05:51,250 --> 00:05:58,140
OK, as well as also BTR, BTR B at this point also points to number two.
93
00:05:58,470 --> 00:06:04,710
So both of them, BTR and BTR, b, both of them point to the same variable NUM two.
94
00:06:05,190 --> 00:06:08,370
And when we say right now BTR B equals two.
95
00:06:08,370 --> 00:06:14,010
BTR A, what is going to happen is that we are not going to change anything.
96
00:06:14,040 --> 00:06:19,910
BTR B is going to point where BTR eight points to an BTR, eight points to NUM two.
97
00:06:20,600 --> 00:06:20,900
Right.
98
00:06:20,950 --> 00:06:22,550
We see that it happens before.
99
00:06:22,560 --> 00:06:23,910
So nothing changes.
100
00:06:24,270 --> 00:06:25,500
Still remain the same.
101
00:06:25,770 --> 00:06:30,600
Both of them point to number two and none of them points to num one.
102
00:06:30,930 --> 00:06:38,220
So if we try to bring the result on the screen, we can see that it still remains six and ten because
103
00:06:38,280 --> 00:06:43,830
we did not change any of the values of NUM one and two we just modified.
104
00:06:43,860 --> 00:06:48,590
Who is pointing to we're just modifying the pointer variables.
105
00:06:49,320 --> 00:06:52,170
And if we are going to print the result here.
106
00:06:52,340 --> 00:06:52,570
OK.
107
00:06:52,650 --> 00:06:54,890
So pointer BTR a and point there.
108
00:06:54,910 --> 00:07:02,580
BTR B we know that we access to the address of the variable that we point to and we know that both of
109
00:07:02,580 --> 00:07:03,770
them point to number two.
110
00:07:04,050 --> 00:07:07,840
So the result is going to be ten and ten.
111
00:07:08,130 --> 00:07:09,750
So that's very important.
112
00:07:09,800 --> 00:07:13,200
Guys, this line twenty five is very important to understand.
113
00:07:13,950 --> 00:07:15,960
So is there a last example?
114
00:07:15,990 --> 00:07:23,460
Our last printf line, we are going to use this sign meant to assign some new value that is stored inside
115
00:07:23,460 --> 00:07:26,040
of the variable that BTR B points to.
116
00:07:26,150 --> 00:07:28,610
And this variable, we said is simply write.
117
00:07:28,620 --> 00:07:30,130
It was what it was to.
118
00:07:30,220 --> 00:07:30,510
Right.
119
00:07:30,650 --> 00:07:31,470
So num two.
120
00:07:31,800 --> 00:07:38,760
So we know is that very instead of these pointer B, we are getting the value inside of NUM two, which
121
00:07:38,760 --> 00:07:40,410
is currently just ten.
122
00:07:40,710 --> 00:07:43,520
So at this point no one will be equal to ten.
123
00:07:43,770 --> 00:07:50,040
And of course we can calculate num to name two will be equal to 10 minus three, which is a total of
124
00:07:50,040 --> 00:07:50,490
seven.
125
00:07:50,940 --> 00:07:56,000
And we can say that in the last print off-line we are going to print ten.
126
00:07:56,460 --> 00:07:56,740
OK.
127
00:07:56,890 --> 00:07:59,600
We're going to print num one equals two.
128
00:07:59,650 --> 00:08:07,320
So of one equals two ten and num two equals equals num two equals two seven.
129
00:08:07,470 --> 00:08:10,430
So that's basically it for these exercise guys.
130
00:08:10,470 --> 00:08:14,610
And we practice how pointers work, what they store inside of them.
131
00:08:14,610 --> 00:08:17,670
How do they point to another variable.
132
00:08:17,700 --> 00:08:21,710
And in this example, this variable was of an integer type.
133
00:08:21,810 --> 00:08:26,010
Of course it will be very similar if we would have used here a floating point.
134
00:08:26,040 --> 00:08:28,800
So it may be a free float, floating point type.
135
00:08:29,190 --> 00:08:35,910
And then, of course, we would expect that these variable BTR A, which is a pointer to a float, will
136
00:08:35,910 --> 00:08:39,540
not point to number one when number one is just an integer.
137
00:08:39,750 --> 00:08:44,670
So we expected that it will point to a very variable of a floating point type.
138
00:08:44,790 --> 00:08:49,200
Is the same you can do just with charts and so on and so forth.
139
00:08:49,290 --> 00:08:51,180
So thank you so much for watching.
140
00:08:51,450 --> 00:08:52,080
Give it a try.
141
00:08:52,080 --> 00:08:57,240
And when you're on your own, make sure that all the printed results that we've discussed right now
142
00:08:57,240 --> 00:09:01,440
are exactly as you got them on your piece and paper.
143
00:09:01,980 --> 00:09:04,350
And until the next video, I'll see you there.
12833
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.