All language subtitles for 2. Pointers - Why using Pointers

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,360 --> 00:00:00,720 OK. 2 00:00:00,900 --> 00:00:07,980 So let's proceed with this WAB function and generally what we've sound about functions is that we may 3 00:00:07,980 --> 00:00:14,520 think of them as some certain people with certain functionalities, or basically we can think of every 4 00:00:14,520 --> 00:00:21,210 function as some sort of room or a lab which is responsible for the accomplishment of some task. 5 00:00:21,360 --> 00:00:27,300 For example, we can see here that we have the driver, which is responsible for driving the painter, 6 00:00:27,300 --> 00:00:28,780 the cooker and so on. 7 00:00:28,800 --> 00:00:29,040 Right. 8 00:00:29,340 --> 00:00:33,060 These are mainly our function or analogy, two functions. 9 00:00:33,210 --> 00:00:38,670 And we also said that we can think of the main function as our current room is our main room. 10 00:00:38,840 --> 00:00:45,210 And in this main room, we have two variables called A and B, which are just two boxes with the names 11 00:00:45,240 --> 00:00:50,250 A and B, with the label C and B, and these two boxes sit in the main room. 12 00:00:50,280 --> 00:00:55,750 Okay, we have the main room, the main function, and both of these variables just sitting there. 13 00:00:55,860 --> 00:01:02,580 And also we've said that there is a swap function or we can say there is another room called Swap, 14 00:01:02,900 --> 00:01:04,080 that there are seats. 15 00:01:04,080 --> 00:01:10,930 Some guy who is responsible for this swap functionality between given two numbers that are answer to 16 00:01:11,040 --> 00:01:14,780 to these these are swap room in the way we pass. 17 00:01:14,790 --> 00:01:21,150 In this example, the two values from the main room to the swap room is accomplished not by sending 18 00:01:21,150 --> 00:01:22,110 these boxes. 19 00:01:22,110 --> 00:01:29,620 The boxes themselves are A and B, we do not send them, but rather we're just sending their values 20 00:01:29,670 --> 00:01:31,260 a copy of their values. 21 00:01:31,470 --> 00:01:37,230 For example, five and seven like we can see here if we initialize them to these values. 22 00:01:37,380 --> 00:01:44,550 So by saying just sending their values, what we mean is simply sending some copy of these values. 23 00:01:45,150 --> 00:01:46,620 So think of it this way. 24 00:01:46,770 --> 00:01:50,400 If you would like to use this one function in the example we've seen previously. 25 00:01:50,850 --> 00:01:57,000 Then when you call this one function, you would open the door of the other room of the swap room, 26 00:01:57,300 --> 00:02:00,360 which is responsible for all the swapping functionality. 27 00:02:00,720 --> 00:02:07,070 And you will not take the two boxes you have here in the main function and pass them to the swap room. 28 00:02:07,080 --> 00:02:15,180 You just want take the boxes, but rather what you will do is just opening the door and screaming that 29 00:02:15,300 --> 00:02:16,860 the two values should chair. 30 00:02:16,980 --> 00:02:20,580 That should be changed are just five and seven. 31 00:02:20,610 --> 00:02:23,160 Okay, so you're just passed by value. 32 00:02:23,190 --> 00:02:26,970 Just a copy of these values, but not the boxes themselves. 33 00:02:27,040 --> 00:02:30,960 You see the difference, and that's called passing by value. 34 00:02:30,990 --> 00:02:37,530 So once again, you from the main you from the main room, you just screen the two values inside boxes, 35 00:02:37,590 --> 00:02:40,040 A and B, and this is function. 36 00:02:40,040 --> 00:02:42,420 Here is what you screen to it. 37 00:02:42,510 --> 00:02:42,830 OK. 38 00:02:42,900 --> 00:02:46,740 So I hear that the two numbers are five and seven. 39 00:02:47,070 --> 00:02:53,570 And I store them inside of my two local variables, number one and number two, which are part of our 40 00:02:53,580 --> 00:02:54,280 swap room. 41 00:02:54,500 --> 00:02:59,220 Sophus, what function does not know anything about the variables in the main function? 42 00:02:59,460 --> 00:03:03,360 He does not even it doesn't even know that they exist. 43 00:03:03,750 --> 00:03:08,250 He just are in this what room gate takes a copy of them. 44 00:03:08,580 --> 00:03:10,020 So I hope that's clear. 45 00:03:10,260 --> 00:03:15,520 And now let's let's take a look at how on this what functionalities is this? 46 00:03:15,520 --> 00:03:18,090 What function will work in this case? 47 00:03:18,150 --> 00:03:18,400 OK. 48 00:03:18,960 --> 00:03:22,950 So what happens inside of the swap function is something like this. 49 00:03:23,300 --> 00:03:25,210 We create a temp variable. 50 00:03:25,290 --> 00:03:29,460 We swap the values between the boxes of NUM one and, um, two. 51 00:03:29,850 --> 00:03:32,720 And everything seems to be working as expected. 52 00:03:32,730 --> 00:03:33,100 Right. 53 00:03:33,300 --> 00:03:38,460 You can even try and print the values of number one and, um, two inside of the swap function. 54 00:03:38,730 --> 00:03:42,300 And you will see that they were swapped as expected. 55 00:03:42,450 --> 00:03:50,970 But in here comes the big but you can clearly see that the variables A and B in the main function remains 56 00:03:51,030 --> 00:03:51,720 the same. 57 00:03:51,810 --> 00:03:52,770 They didn't change. 58 00:03:52,770 --> 00:03:53,940 It changed at all. 59 00:03:54,060 --> 00:03:58,680 And basically, that's something that we we we didn't want. 60 00:03:58,700 --> 00:03:58,950 Right. 61 00:03:58,980 --> 00:04:06,450 We we wanted to change A and B, we didn't want to change number one in, um, to inside of some swap 62 00:04:06,450 --> 00:04:06,710 room. 63 00:04:06,720 --> 00:04:12,750 We wanted to see the result in the main room that A and B were swapped. 64 00:04:12,900 --> 00:04:20,520 And at first glance, if we take, for example, the swap function, we think for to ourselves that 65 00:04:20,790 --> 00:04:22,980 both of the rare variables should change. 66 00:04:23,490 --> 00:04:27,840 But as we've said previously, we are passing through the swap function. 67 00:04:28,080 --> 00:04:35,280 We are just passing a copy of these values of A and B. And now the variables themselves, not the boxes 68 00:04:35,280 --> 00:04:35,760 themselves. 69 00:04:36,190 --> 00:04:41,850 And then it means that we do not take these boxes A and B and swap between their content. 70 00:04:42,150 --> 00:04:46,860 We are just working with a copy of its content of five and seven. 71 00:04:47,070 --> 00:04:50,400 And it doesn't matter for a and being the main function. 72 00:04:50,550 --> 00:04:54,090 So variables A and B remain untouched. 73 00:04:54,570 --> 00:04:59,850 So let's take another look at this swap function and try to understand maybe. 74 00:05:00,000 --> 00:05:07,160 The little bit further for what's going on here and maybe what should we do in this case, maybe the 75 00:05:07,160 --> 00:05:09,350 pointers may help us, perhaps, right? 76 00:05:09,380 --> 00:05:10,810 We are in the point resections. 77 00:05:11,150 --> 00:05:13,700 So let's see what what do we have here? 78 00:05:13,790 --> 00:05:16,340 So the code the code will look like this. 79 00:05:16,370 --> 00:05:16,580 OK. 80 00:05:16,670 --> 00:05:18,730 So we have this void swab. 81 00:05:18,800 --> 00:05:19,040 OK. 82 00:05:19,370 --> 00:05:21,200 The function does not return anything. 83 00:05:21,200 --> 00:05:29,390 He just gets to values and it stores them inside of num one and um, two creates a temp for a temp variable 84 00:05:29,930 --> 00:05:32,000 to assist in the swap functionality. 85 00:05:32,030 --> 00:05:35,150 And then it does all its unnecessary things. 86 00:05:35,270 --> 00:05:41,510 So what we expect once again, just to emphasize it, what we expect are it doesn't work clearly. 87 00:05:41,750 --> 00:05:46,310 But what we want and what we expect that a functional will do is that we send it. 88 00:05:46,570 --> 00:05:53,740 The variable is A and B, and it will return as this variable as it will make somehow that the values 89 00:05:53,750 --> 00:05:59,240 in these two variables were changed from five to seven and from seven to five. 90 00:05:59,300 --> 00:06:05,600 OK, and just by using these approaches that we have here and that we've seen here are simply won't 91 00:06:05,600 --> 00:06:06,140 work. 92 00:06:06,470 --> 00:06:10,040 And that's exactly when pointers enter the game. 93 00:06:10,130 --> 00:06:17,210 So what we want to do is to pass the variables and be themselves or at least the way to access them 94 00:06:17,210 --> 00:06:20,430 directly and not just the copy of their values. 95 00:06:20,450 --> 00:06:20,840 Right. 96 00:06:20,960 --> 00:06:27,440 Because if we want to change them, then what do we have to do is give some way to access them, the 97 00:06:27,440 --> 00:06:31,550 real them, the real boxes, and not just a copy of A and B.. 98 00:06:31,820 --> 00:06:37,070 And what is that we know about variables that can really help us to identify them. 99 00:06:37,430 --> 00:06:39,110 And you're you're right. 100 00:06:39,200 --> 00:06:41,240 And we can see it right here on the screen. 101 00:06:41,540 --> 00:06:48,770 Something special about variable, something unique is their address and and addresses some unique place 102 00:06:48,860 --> 00:06:53,750 in the memory of your computer where the variable itself resides. 103 00:06:53,990 --> 00:07:01,750 So that's a great way to access a given variable just by knowing where it seats. 104 00:07:01,850 --> 00:07:02,060 OK. 105 00:07:02,120 --> 00:07:03,670 It's just like where you live. 106 00:07:03,710 --> 00:07:03,960 OK. 107 00:07:04,010 --> 00:07:07,820 We can access where you live because we know your address. 108 00:07:07,850 --> 00:07:14,390 So similarly, we can access variables in the memory of your computer just by using their address. 109 00:07:14,420 --> 00:07:14,600 OK. 110 00:07:14,840 --> 00:07:16,280 You should already know it by now. 111 00:07:16,310 --> 00:07:18,440 But I'm just making a quick reminder. 112 00:07:18,590 --> 00:07:25,850 And that summarizes that if at any point and any time we know the address of a variable, we can basically 113 00:07:26,240 --> 00:07:28,460 directly access it and modified. 114 00:07:28,490 --> 00:07:29,510 However we like. 115 00:07:29,780 --> 00:07:33,020 Doesn't matter where we are accessing it from. 116 00:07:33,230 --> 00:07:38,900 For me, for example, in the main functioning, the swap function, as long as we do it kind of legally. 117 00:07:38,900 --> 00:07:39,410 All right. 118 00:07:39,560 --> 00:07:46,490 So what we want to do is instead of calling this warb function and passing it a copy of the values which 119 00:07:46,490 --> 00:07:51,230 we've seen previously, that it brings us pretty much nowhere. 120 00:07:51,980 --> 00:07:58,820 What we would like to do is to pass the address of every variable, to pass the address of Variable 121 00:07:58,850 --> 00:08:01,720 A and to pass the address of variable B. 122 00:08:02,270 --> 00:08:08,210 And by doing so, this swap function will receive addresses of the specified variables. 123 00:08:08,600 --> 00:08:15,890 And then just by knowing the address of where are some variable resides, we will use the concept of 124 00:08:15,890 --> 00:08:19,100 pointers to access a given address. 125 00:08:19,310 --> 00:08:27,200 And to do some things just just that this address to access these are variables through their address. 126 00:08:27,470 --> 00:08:28,190 Is that clear? 127 00:08:28,280 --> 00:08:33,710 And I know this concept is not so easy at first, but once you know the difference between these two 128 00:08:33,710 --> 00:08:40,280 approaches, by sending by value and by reference, which which we are going to talk in these section 129 00:08:40,820 --> 00:08:43,850 pointers will just become a piece of cake for you. 130 00:08:43,890 --> 00:08:44,240 OK. 131 00:08:44,480 --> 00:08:52,490 It will be so easy once you understand the logic and the core B behind what's happening in your computer 132 00:08:52,490 --> 00:09:00,920 as memory and how you store values which hold addresses of other variables, which what we are exactly 133 00:09:00,920 --> 00:09:01,610 doing right now. 134 00:09:01,620 --> 00:09:08,180 I think that once you get this whole idea, maybe watch this video also twice just to emphasize and 135 00:09:08,180 --> 00:09:14,390 to make sure you got everything that we said, because as I said previously, it's not so easy when 136 00:09:14,390 --> 00:09:16,910 you hear this topic for the first time. 137 00:09:16,960 --> 00:09:17,210 OK. 138 00:09:17,420 --> 00:09:21,020 So now let's take another look and see how it works. 139 00:09:21,380 --> 00:09:23,270 So we have the main function, OK? 140 00:09:23,390 --> 00:09:28,550 And we have for two variables, A and B, both of them store some value. 141 00:09:28,580 --> 00:09:30,350 A store is five has a value. 142 00:09:30,350 --> 00:09:32,270 B stores seven is a value. 143 00:09:32,300 --> 00:09:33,650 Think of it as just now. 144 00:09:33,830 --> 00:09:34,180 I don't know. 145 00:09:34,190 --> 00:09:34,650 Shoes. 146 00:09:35,550 --> 00:09:38,630 The couple amount, the amount of shoes inside of these variables. 147 00:09:38,990 --> 00:09:43,330 And also, we know we have this label of address, A, an address. 148 00:09:43,340 --> 00:09:50,780 B, we also have an associated address where these variables reside in the memory of your computer. 149 00:09:50,900 --> 00:09:53,690 So in this warped function, we have two parameters. 150 00:09:53,720 --> 00:09:58,850 Let's call them p, num one and be numb to these variables. 151 00:09:58,880 --> 00:09:59,720 What they have. 152 00:09:59,770 --> 00:10:03,090 To do is simply to receive and store an address. 153 00:10:03,170 --> 00:10:03,470 OK? 154 00:10:03,530 --> 00:10:07,340 They will receive and store and dress that we pass to them. 155 00:10:07,370 --> 00:10:07,590 OK. 156 00:10:07,640 --> 00:10:11,030 They will hold addresses inside of them as their value. 157 00:10:11,060 --> 00:10:12,160 That's something new. 158 00:10:12,170 --> 00:10:15,140 We didn't talk about it in the previous sections. 159 00:10:15,260 --> 00:10:24,470 And then when we pass the addresses to p num one and Piñon to OK, they will be held as values and they 160 00:10:24,470 --> 00:10:25,450 will know OK. 161 00:10:25,540 --> 00:10:30,710 They will know where the variables A and B are stored. 162 00:10:30,740 --> 00:10:31,040 OK. 163 00:10:31,100 --> 00:10:33,650 They will know how to access these variables. 164 00:10:33,950 --> 00:10:36,690 Just by saying, OK, I know where they reside. 165 00:10:36,950 --> 00:10:38,400 I can also access them. 166 00:10:38,450 --> 00:10:38,680 OK. 167 00:10:39,050 --> 00:10:39,860 Makes sense. 168 00:10:39,980 --> 00:10:48,590 So by pointing to them, by pointing through B number one and piñon to two variables, A and B which 169 00:10:48,590 --> 00:10:50,540 are inside of the main function. 170 00:10:50,870 --> 00:10:57,230 So just by pointing from this WAB function to the main function variables, we will be able simply to 171 00:10:57,260 --> 00:11:02,540 modify the content itself inside of these variables, A and B.. 172 00:11:02,750 --> 00:11:04,660 That's that's just awesome, guys. 173 00:11:04,700 --> 00:11:06,200 You don't know how many topics. 174 00:11:06,590 --> 00:11:13,970 How many are structures, programs, courses are built just on this understanding of pointers. 175 00:11:14,090 --> 00:11:15,470 So these be No. 176 00:11:15,560 --> 00:11:21,230 One and piñon two parameters that the swap function has are of a special type. 177 00:11:21,260 --> 00:11:25,160 Let's say they let's call it this way because they do not hold. 178 00:11:25,220 --> 00:11:29,160 Stand third are integer or a floating point type. 179 00:11:29,270 --> 00:11:33,110 Worse, some some other value that we learned in the previous videos. 180 00:11:33,620 --> 00:11:35,720 It simply stores an address. 181 00:11:35,960 --> 00:11:41,900 So they hold addresses that in these addresses reside some values. 182 00:11:41,900 --> 00:11:45,670 For example, five and seven in A and B and be No. 183 00:11:45,670 --> 00:11:50,580 One holds the address of A and being on two holds the address of B. 184 00:11:50,750 --> 00:11:52,490 They simply point somewhere. 185 00:11:52,490 --> 00:11:56,330 And that's exactly why they here are called pointers. 186 00:11:56,460 --> 00:11:56,800 Okay. 187 00:11:56,930 --> 00:12:01,720 So I hope this animated and visualized explanation is clear to you guys. 188 00:12:01,730 --> 00:12:07,760 I don't think that a lot of teachers really teach this tough topic, and that's a hell of a tough topic. 189 00:12:08,180 --> 00:12:11,240 I don't think that a lot of teachers teach it this way. 190 00:12:11,240 --> 00:12:19,430 And I know in my experience, in my opinion, that's why students are struggling to understand what 191 00:12:19,430 --> 00:12:22,340 what is pointers and why we can use them. 192 00:12:22,700 --> 00:12:27,470 But I think that this is the best approach to understand what's going on behind the scenes. 193 00:12:27,770 --> 00:12:31,790 And I'll just do quit because it's too difficult to grasp it first. 194 00:12:32,240 --> 00:12:37,160 So I hope that's clear because it's very important that you understand the topic. 195 00:12:37,460 --> 00:12:44,450 It's the basis for the advanced sections and basically a lot of things are going to build to be built 196 00:12:44,450 --> 00:12:44,960 upon it. 197 00:12:45,110 --> 00:12:47,150 And this is it for these video. 198 00:12:47,150 --> 00:12:49,160 Guys like screen is black. 199 00:12:49,220 --> 00:12:52,610 We are over with this video. 200 00:12:53,210 --> 00:12:54,440 I'll see you in the next one. 201 00:12:54,590 --> 00:12:55,300 Have a nice day. 18832

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.