1 00:00:00,720 --> 00:00:08,550 Pointers share several characteristics with arrays, so pointers in called object location always encode 2 00:00:08,550 --> 00:00:12,720 the location and the length of the contiguous objects. 3 00:00:12,840 --> 00:00:20,340 At the slightest provocation, an array will decay into a pointer, so the key the array loses length 4 00:00:20,340 --> 00:00:24,980 information and converts the pointer to the arrays first element. 5 00:00:24,990 --> 00:00:32,820 So for example, I want to write some example here, my array here, and we will create a array and 6 00:00:32,820 --> 00:00:40,560 we will put three numbers in it six, three, six and nine here. 7 00:00:41,310 --> 00:00:50,100 Then we will create an integer here integer pointer key here a Peter. 8 00:00:50,960 --> 00:00:54,710 All right, Raptors here. 9 00:00:55,430 --> 00:00:57,320 Um, my array. 10 00:00:58,410 --> 00:00:59,400 That's not my area. 11 00:00:59,520 --> 00:01:01,560 So this will point to three. 12 00:01:02,220 --> 00:01:04,410 And let's print it. 13 00:01:07,250 --> 00:01:10,070 Here we will use the add the reference operator. 14 00:01:11,820 --> 00:01:12,930 Okay. 15 00:01:13,900 --> 00:01:15,160 Raptor. 16 00:01:16,800 --> 00:01:17,880 And print it. 17 00:01:18,280 --> 00:01:18,630 Oops. 18 00:01:19,140 --> 00:01:19,710 Sorry. 19 00:01:20,910 --> 00:01:21,510 Here. 20 00:01:21,690 --> 00:01:23,910 We will get the pointer here as well. 21 00:01:23,970 --> 00:01:27,570 But I want to print it as an array here. 22 00:01:28,450 --> 00:01:33,200 And as you can see here, we got the three here and here. 23 00:01:33,220 --> 00:01:43,630 So first we initialize the an integer array to the my array here with three elements, three, six and 24 00:01:43,630 --> 00:01:44,920 9 to 3 elements. 25 00:01:45,250 --> 00:01:56,290 So next you initialize the integer pointer here to a raptor, which the case to a pointer. 26 00:01:56,590 --> 00:02:08,110 After initialization, the key raptor points to the first element of the my array here, which as you 27 00:02:08,110 --> 00:02:17,680 saw here this when we print this just as an array as an variable, we got a tree the first element of 28 00:02:17,680 --> 00:02:18,490 my array. 29 00:02:19,390 --> 00:02:26,830 So we are now we're going to initialize an array containing colleague and we will pass the array to 30 00:02:26,830 --> 00:02:29,270 function as pointer. 31 00:02:29,290 --> 00:02:32,540 So firstly, let's create a struct name. 32 00:02:32,560 --> 00:02:33,610 Click here. 33 00:02:36,510 --> 00:02:39,100 Or we instead of calligraphy, can create them. 34 00:02:39,450 --> 00:02:43,290 The car model names make model, uh, make names. 35 00:02:43,290 --> 00:02:50,790 So struct car, car series, car and name will Character name. 36 00:02:51,060 --> 00:02:52,890 Character name. 37 00:02:53,010 --> 00:02:56,420 This is, as you know, strings is just a characters. 38 00:02:56,430 --> 00:03:02,310 So that's why we're going to we used here character name 2000. 39 00:03:02,310 --> 00:03:05,520 Uh, 200, uh, 56. 40 00:03:07,500 --> 00:03:11,470 So it can contain 256 characters in a row. 41 00:03:11,490 --> 00:03:21,330 So then we will use the creative print name function void print, name, function here car. 42 00:03:22,480 --> 00:03:23,860 And car. 43 00:03:24,310 --> 00:03:24,610 P. 44 00:03:24,610 --> 00:03:24,840 T. 45 00:03:24,880 --> 00:03:25,330 R. 46 00:03:26,860 --> 00:03:27,310 Here. 47 00:03:27,340 --> 00:03:29,890 Plaintiff Uh. 48 00:03:30,280 --> 00:03:34,420 Se form a specified car and new line. 49 00:03:35,350 --> 00:03:43,090 Then we will use a car p t r But we will use the member of operator here name. 50 00:03:43,380 --> 00:03:50,980 And as you can see here, so it's actually not print name, it's just a print F here. 51 00:03:53,490 --> 00:03:58,510 And then let's write our main function here. 52 00:03:58,530 --> 00:04:03,060 So car, my garage here. 53 00:04:04,120 --> 00:04:16,240 And we will add three car names, for example, BMW, Mercedes, Mercedes and Ford. 54 00:04:17,150 --> 00:04:18,050 First year. 55 00:04:19,220 --> 00:04:19,730 For. 56 00:04:20,580 --> 00:04:22,460 Then we will print this print. 57 00:04:22,470 --> 00:04:25,080 Name my character. 58 00:04:32,750 --> 00:04:33,830 As you can see here. 59 00:04:34,830 --> 00:04:39,070 The prince name function the case into a pointer. 60 00:04:39,090 --> 00:04:44,880 When you call the prince name so because arrays decay into pointer, so are first element. 61 00:04:45,930 --> 00:04:58,490 So my car PDR here my carburetor at points to the first car in the car names here my character. 62 00:04:58,920 --> 00:05:03,360 So there's another already okay in the next lecture as well. 63 00:05:03,540 --> 00:05:06,300 So you use the row operator here. 64 00:05:07,410 --> 00:05:15,750 Here you use the arrow operator to access the name member of the car pointer to buy a car. 65 00:05:15,750 --> 00:05:16,530 Peter. 66 00:05:17,250 --> 00:05:21,260 So which itself is a character array as we declared here. 67 00:05:21,270 --> 00:05:32,670 So the PRINTF format specified for SW expects SC style string, which is a character pointer and name 68 00:05:32,670 --> 00:05:36,700 the case in the pointer to satisfy print F. 69 00:05:40,110 --> 00:05:44,340 And now we're going to handle the decay here. 70 00:05:44,580 --> 00:05:54,370 So often you pass arrays as two arguments, a pointer to the first array element and the arrays length. 71 00:05:54,390 --> 00:06:02,880 So that mechanism that enables this pattern is square braces, which work with the pointers, just as 72 00:06:02,880 --> 00:06:03,810 with arrays. 73 00:06:04,230 --> 00:06:05,520 So now. 74 00:06:06,330 --> 00:06:12,900 Uh, we will employ this technique in and edit and reprogram this code here. 75 00:06:13,110 --> 00:06:17,970 So in print names, we're going to add the for loop here. 76 00:06:19,030 --> 00:06:21,490 So here. 77 00:06:22,610 --> 00:06:23,320 For. 78 00:06:24,390 --> 00:06:25,010 Size. 79 00:06:25,560 --> 00:06:27,260 I will explain all of this court later. 80 00:06:27,270 --> 00:06:27,990 Don't worry. 81 00:06:28,470 --> 00:06:30,120 Sighs t. 82 00:06:30,540 --> 00:06:32,070 And we're going to criticize. 83 00:06:32,070 --> 00:06:36,060 Still being named, uh, and we will assign it to zero. 84 00:06:36,570 --> 00:06:45,540 And while e is less than, um, e is less than actual, we're going to take another parameter here. 85 00:06:45,630 --> 00:06:48,120 Size t the. 86 00:06:49,600 --> 00:07:02,740 And cause while he is less than in cars and cars, then increment E by one. 87 00:07:03,780 --> 00:07:11,430 And here we're going to use the printer function As you as you saw earlier, we use the member of operator, 88 00:07:11,430 --> 00:07:14,190 but this time we're going to use a different format here. 89 00:07:15,540 --> 00:07:17,830 So this will take us here. 90 00:07:17,850 --> 00:07:20,760 Shrinks, sisters, shrinks here. 91 00:07:21,180 --> 00:07:22,620 We won't change that. 92 00:07:22,620 --> 00:07:29,640 But we will change this here because we will pass the another argument to this format specified here. 93 00:07:30,870 --> 00:07:33,090 That is the. 94 00:07:36,430 --> 00:07:36,790 Car. 95 00:07:36,900 --> 00:07:42,490 Peter Actually, now we're going to use the just here. 96 00:07:44,110 --> 00:07:45,010 Cars. 97 00:07:45,580 --> 00:07:46,360 Cars. 98 00:07:47,050 --> 00:07:49,180 We will we change the parameter as well. 99 00:07:49,510 --> 00:07:58,180 So now we're going to use the cars e here we will pass E and then that here name. 100 00:08:00,130 --> 00:08:07,120 So and also we will here, as you can see, we will we won't change this. 101 00:08:07,840 --> 00:08:09,880 We have three. 102 00:08:11,210 --> 00:08:14,960 This rings in my garage, which is. 103 00:08:15,890 --> 00:08:18,500 BMW, Mercedes and Ford. 104 00:08:19,790 --> 00:08:20,420 Then. 105 00:08:21,720 --> 00:08:26,790 We will use the print names, function prints, and we will call the print names function. 106 00:08:27,000 --> 00:08:34,260 And first, we're going to pass the my garage as on first parameter and next. 107 00:08:35,690 --> 00:08:38,150 We will sizeof. 108 00:08:39,240 --> 00:08:39,750 Here. 109 00:08:41,110 --> 00:08:42,100 Size of. 110 00:08:54,230 --> 00:08:55,790 Size of my garage. 111 00:08:58,830 --> 00:08:59,490 Here. 112 00:08:59,700 --> 00:09:02,190 Divide by size of. 113 00:09:03,180 --> 00:09:03,930 Um. 114 00:09:06,810 --> 00:09:08,130 Size of car. 115 00:09:08,700 --> 00:09:10,650 Yeah, size of car. 116 00:09:10,650 --> 00:09:12,540 As you can see here, this is a strength. 117 00:09:13,870 --> 00:09:19,900 So now we can execute our function here, our code here. 118 00:09:19,900 --> 00:09:25,510 And as you can see here, we got a tree of our elements, array elements here. 119 00:09:25,840 --> 00:09:31,120 So now let's explain this cords by line by line. 120 00:09:31,120 --> 00:09:37,090 So the print names function accepts an array in. 121 00:09:37,900 --> 00:09:41,410 Two arguments here, as you can see here. 122 00:09:42,430 --> 00:09:44,230 The first is. 123 00:09:47,340 --> 00:09:50,700 The first is the cars. 124 00:09:52,080 --> 00:09:57,000 And the second is number of elements in and car here. 125 00:09:57,000 --> 00:10:05,340 So within the print names you iterate with the for loop and an index E here. 126 00:10:05,430 --> 00:10:11,160 So the value of E iterates from zero here zero. 127 00:10:11,910 --> 00:10:17,640 Two, um, MN colleagues, minus one. 128 00:10:18,270 --> 00:10:28,620 So then you extract the corresponding cooling nine by accessing the here eight element here and then 129 00:10:28,620 --> 00:10:30,990 get the name member. 130 00:10:31,830 --> 00:10:32,280 Here. 131 00:10:33,780 --> 00:10:41,160 The pointer plus size approach to passing arrays is ubiquitous since sister APIs, for example, in 132 00:10:41,160 --> 00:10:45,810 Windows or Linux programming systems.