1 00:00:02,300 --> 00:00:06,920 You can either have typed pointers or a void pointer here. 2 00:00:06,920 --> 00:00:14,480 So the typed pointers will access the memory as if it's specified type to use If you cast a pointer 3 00:00:14,480 --> 00:00:20,510 to a different type and the reference ID, the memory will be treated as containing the cast type. 4 00:00:20,540 --> 00:00:26,300 It really makes sense to do this, but the void pointer cannot bear the reference, so you can never 5 00:00:26,300 --> 00:00:29,080 access data through the void pointer. 6 00:00:29,090 --> 00:00:32,990 So to exit the data you have to cast the pointer here. 7 00:00:33,020 --> 00:00:40,440 The full reason for this void pointer type is that it can point to anything in general. 8 00:00:40,460 --> 00:00:46,430 Void pointer should only be used when the type does not matter to that function. 9 00:00:46,430 --> 00:00:54,980 So for example, the c malloc function returns the void pointer because the function merely allocates 10 00:00:54,980 --> 00:00:55,640 memory. 11 00:00:55,670 --> 00:00:58,490 It does not care what the memory will be used for. 12 00:00:59,780 --> 00:01:04,580 So here pointers also can declare it as a cost here. 13 00:01:04,700 --> 00:01:11,810 So which depending on where you apply, it means that the memory the pointer points to is read only 14 00:01:11,810 --> 00:01:16,010 through the pointer or the value of the pointer is read only. 15 00:01:16,040 --> 00:01:20,350 So now I want to create some character. 16 00:01:20,700 --> 00:01:21,680 Consider this. 17 00:01:21,800 --> 00:01:25,910 We're going to make a character pizza cost here. 18 00:01:26,960 --> 00:01:31,130 So hello And then pointer. 19 00:01:31,130 --> 00:01:33,650 See here. 20 00:01:33,740 --> 00:01:34,190 H. 21 00:01:34,190 --> 00:01:34,730 Here. 22 00:01:35,030 --> 00:01:36,680 And const. 23 00:01:37,590 --> 00:01:41,190 Character Pizzey here. 24 00:01:41,190 --> 00:01:44,790 See, I'm going to comment about all of this. 25 00:01:44,790 --> 00:01:51,360 So for more understanding here and make it look nice and Pizzey. 26 00:01:52,570 --> 00:01:53,680 We hear. 27 00:01:56,910 --> 00:01:57,840 And. 28 00:01:58,810 --> 00:02:00,010 Character. 29 00:02:03,890 --> 00:02:04,760 Closed. 30 00:02:06,700 --> 00:02:07,540 Skippy. 31 00:02:09,860 --> 00:02:11,480 And make it see. 32 00:02:12,500 --> 00:02:25,430 And c p calls e on the underscore e here and C++ or C++ actually, because we're going to use this C++. 33 00:02:25,970 --> 00:02:32,150 So now the C can be used as pointer. 34 00:02:33,620 --> 00:02:38,720 C can be used as a pointer. 35 00:02:39,020 --> 00:02:42,470 And here it's okay to write like that. 36 00:02:42,680 --> 00:02:43,280 Okay. 37 00:02:43,280 --> 00:02:45,140 But can write. 38 00:02:46,020 --> 00:02:48,870 Where I threw the pointer. 39 00:02:50,120 --> 00:02:52,280 Here and here. 40 00:02:54,000 --> 00:03:03,630 As you can see, we declared, and we're going to convert the pointer pointer pointer to constant. 41 00:03:04,300 --> 00:03:05,500 And here. 42 00:03:06,210 --> 00:03:07,670 It's okay, too. 43 00:03:07,680 --> 00:03:10,740 And it can read the memory. 44 00:03:10,780 --> 00:03:13,850 Memory pointed to here. 45 00:03:13,860 --> 00:03:24,690 But here, as you can see here, the ID showed us an error because we cannot write to the memory. 46 00:03:25,780 --> 00:03:31,000 And here it's okay because it's constant pointer. 47 00:03:31,030 --> 00:03:33,790 We're going to create a new constant pointer here. 48 00:03:33,940 --> 00:03:35,470 Constant pointer. 49 00:03:35,500 --> 00:03:38,890 And here we are. 50 00:03:38,980 --> 00:03:40,110 We can write. 51 00:03:40,120 --> 00:03:43,690 We can write true the pointer. 52 00:03:43,750 --> 00:03:47,130 And we cannot point it here. 53 00:03:47,140 --> 00:03:48,550 This C++. 54 00:03:48,550 --> 00:03:52,840 We cannot point to anything else. 55 00:03:53,230 --> 00:03:54,400 Anything else? 56 00:03:55,710 --> 00:04:07,020 So here the PTC is a pointer to a constant connector that is the output you can change the PTC points 57 00:04:07,020 --> 00:04:13,340 to and you can read what it points to, but you cannot use it to change the memory here. 58 00:04:13,350 --> 00:04:18,570 So on the other hand, the c, p here, c p here. 59 00:04:21,400 --> 00:04:23,260 The CP is a constant pointer. 60 00:04:23,770 --> 00:04:30,730 So which means you can both read and write the memory which the pointer points to, but you cannot change 61 00:04:30,730 --> 00:04:32,310 the word it points to. 62 00:04:32,320 --> 00:04:40,240 So it is typical to pass the constant character pointers to functions because the functions do not know 63 00:04:40,240 --> 00:04:44,110 where the string has been allocated or the size of the buffer here. 64 00:04:44,110 --> 00:04:52,690 So the caller may pass a literal which can not be changed, but not that there is not no const operator. 65 00:04:52,690 --> 00:05:00,100 So character const is treated as const character and a pointer to a constant buffer here. 66 00:05:00,130 --> 00:05:05,170 So you can make pointer constant change it or remove it using casts. 67 00:05:05,410 --> 00:05:09,370 And now we're going to create another code here. 68 00:05:11,460 --> 00:05:11,730 Here. 69 00:05:11,730 --> 00:05:17,310 We're going to let's make let's comment this out and make new here. 70 00:05:17,790 --> 00:05:21,510 So here, character, see? 71 00:05:21,810 --> 00:05:24,090 And hello. 72 00:05:26,530 --> 00:05:29,230 And here character points are constant. 73 00:05:29,260 --> 00:05:31,780 Step one, see here. 74 00:05:32,980 --> 00:05:37,060 And we're going to add comments after we complete our code. 75 00:05:37,060 --> 00:05:37,390 Here. 76 00:05:38,320 --> 00:05:38,950 Here. 77 00:05:40,200 --> 00:05:43,440 And cast character Patsy. 78 00:05:45,850 --> 00:05:47,140 And cost costs. 79 00:05:47,140 --> 00:05:49,390 We're going to use cost cost here. 80 00:05:50,320 --> 00:05:52,150 Caused cast. 81 00:05:53,980 --> 00:05:55,630 Post character. 82 00:05:58,060 --> 00:06:00,070 And C.P. one. 83 00:06:03,680 --> 00:06:06,890 And here Pizzey Plus plus. 84 00:06:08,110 --> 00:06:18,380 And after that character concept to coast to coast cast and character post here. 85 00:06:18,490 --> 00:06:19,180 And. 86 00:06:19,180 --> 00:06:20,100 P. 87 00:06:20,130 --> 00:06:20,520 P. 88 00:06:20,560 --> 00:06:21,310 C. 89 00:06:22,150 --> 00:06:25,360 And lastly, RCP to. 90 00:06:26,200 --> 00:06:26,740 A. 91 00:06:28,940 --> 00:06:29,710 Here. 92 00:06:29,810 --> 00:06:30,740 So. 93 00:06:31,590 --> 00:06:37,320 You can make a point that constant change it or remove it by using the casts here. 94 00:06:37,320 --> 00:06:45,000 And this code here does some fairly pointless changing around the const keyboard to prove the point. 95 00:06:45,360 --> 00:06:49,470 So the pointer see p one here. 96 00:06:49,500 --> 00:06:54,450 cp1 and cp2. 97 00:06:55,710 --> 00:06:58,580 Can be used to change the memory they point to. 98 00:06:58,590 --> 00:07:03,570 But once signed, neither can point to other memory here. 99 00:07:03,570 --> 00:07:13,380 So the first concept cast here, as you can see, a cast cast here cast away the const ness to a pointer 100 00:07:13,380 --> 00:07:19,560 that can be changed to point to other memory here, but cannot be used to alter that memory. 101 00:07:19,680 --> 00:07:23,310 So the memory in this case, it's pizza here. 102 00:07:23,550 --> 00:07:34,890 So the second cast casts away the closeness of pizza here so that the memory can be changed through 103 00:07:34,890 --> 00:07:35,640 the pointer. 104 00:07:35,640 --> 00:07:37,140 See P to.