1
00:00:02,110 --> 00:00:06,820
You can either have typed pointers or a void pointer here.

2
00:00:06,820 --> 00:00:14,410
So the typed pointers will access the memory as if it specified type uh, to use if you cast a pointer

3
00:00:14,410 --> 00:00:20,400
to a different type and the reference it, the memory will be treated as containing the cast type.

4
00:00:20,410 --> 00:00:26,230
It really makes sense to do this, but the void pointer cannot bear the reference, so you can never

5
00:00:26,230 --> 00:00:28,990
access data through the void pointer.

6
00:00:28,990 --> 00:00:32,920
So to access the data you have to cast the pointer here.

7
00:00:32,920 --> 00:00:39,310
The full reason for this void pointer type is that it can point to anything.

8
00:00:39,340 --> 00:00:46,360
In general, void pointer should only be used when the type does not matter to that function.

9
00:00:46,360 --> 00:00:54,910
So for example, the C malloc function returns the void pointer because the function merely allocates

10
00:00:54,910 --> 00:00:55,570
memory.

11
00:00:55,570 --> 00:00:58,480
It does not care what the memory will be used for.

12
00:00:59,650 --> 00:01:08,590
So here pointers also can declared as const here so which depending on where you apply it means that

13
00:01:08,590 --> 00:01:15,040
the memory of the pointer points to is read only through the pointer or the value of the pointer is

14
00:01:15,040 --> 00:01:15,970
read only.

15
00:01:15,970 --> 00:01:21,670
So now I want to create some character const this.

16
00:01:21,670 --> 00:01:25,900
We're going to make a character PTC const here.

17
00:01:26,860 --> 00:01:28,900
So hello.

18
00:01:29,440 --> 00:01:31,060
And then pointer.

19
00:01:31,090 --> 00:01:36,640
See here h here and const.

20
00:01:37,520 --> 00:01:41,140
Character PTC here.

21
00:01:41,180 --> 00:01:43,880
See, I'm going to comment it out.

22
00:01:43,880 --> 00:01:44,720
All of this.

23
00:01:44,720 --> 00:01:51,290
So for more understanding here and make it look nice and PTC.

24
00:01:52,530 --> 00:01:53,610
We hear.

25
00:01:56,870 --> 00:01:57,890
And.

26
00:01:58,710 --> 00:01:59,970
Character.

27
00:02:03,880 --> 00:02:04,750
Const.

28
00:02:06,690 --> 00:02:07,230
Keep.

29
00:02:09,850 --> 00:02:10,810
I would make it.

30
00:02:10,840 --> 00:02:11,170
See?

31
00:02:12,370 --> 00:02:22,690
And CP equals here on the underscore E here and C plus plus or C plus plus actually because we're going

32
00:02:22,690 --> 00:02:25,420
to use this C plus plus.

33
00:02:25,750 --> 00:02:32,110
So now, um, the C can be used as a pointer.

34
00:02:33,580 --> 00:02:38,730
See can be used as a pointer.

35
00:02:38,740 --> 00:02:42,460
And here it's okay to write like that.

36
00:02:42,490 --> 00:02:45,100
Okay, but can we write?

37
00:02:45,860 --> 00:02:48,830
Right through the pointer.

38
00:02:50,080 --> 00:02:52,240
Here and here.

39
00:02:53,750 --> 00:03:03,590
As you can see, we declared and we're going to convert the pointer pointer pointer to constant.

40
00:03:04,170 --> 00:03:05,430
And here.

41
00:03:06,050 --> 00:03:13,690
It's okay to and it can read the memory memory pointed to here.

42
00:03:13,700 --> 00:03:24,650
But here, as you can see here, the ID road as an error because we cannot write to the memory.

43
00:03:25,560 --> 00:03:26,820
And here we go.

44
00:03:26,970 --> 00:03:30,900
It's okay because it's constant pointer.

45
00:03:30,930 --> 00:03:33,820
We're going to be creating a new constant pointer here.

46
00:03:33,840 --> 00:03:35,400
Constant pointer.

47
00:03:35,400 --> 00:03:38,820
And here we are.

48
00:03:38,850 --> 00:03:39,990
We can write.

49
00:03:40,020 --> 00:03:47,020
We can write through the pointer and we cannot point it here.

50
00:03:47,040 --> 00:03:52,800
This cplusplus we cannot point to anything else.

51
00:03:53,130 --> 00:03:54,330
Anything else?

52
00:03:55,550 --> 00:04:04,970
So here the C is a pointer to a constant character that is the output.

53
00:04:05,000 --> 00:04:12,290
You can change the points to and you can read what it points to, but you cannot use it to change the

54
00:04:12,290 --> 00:04:13,280
memory here.

55
00:04:13,280 --> 00:04:16,910
So on the other hand, the CP here.

56
00:04:16,940 --> 00:04:18,500
C p here.

57
00:04:21,270 --> 00:04:29,040
The CP is a constant pointer, so which means you can both read and write the memory which the pointer

58
00:04:29,040 --> 00:04:32,220
points to, but you cannot change the way it points to.

59
00:04:32,250 --> 00:04:40,170
So it is typical to pass the constant character pointers to functions because the functions do not know

60
00:04:40,170 --> 00:04:44,040
where the string has been allocated or the size of the buffer here.

61
00:04:44,040 --> 00:04:47,970
So the caller may pass a literal which cannot be changed.

62
00:04:47,970 --> 00:04:52,620
But not that there is a not no const operator.

63
00:04:52,620 --> 00:05:00,030
So character const is treated as const character and a pointer to a constant buffer here.

64
00:05:00,030 --> 00:05:05,130
So you can make pointer constant, uh, change it or remove it using cast.

65
00:05:05,310 --> 00:05:09,330
And now we're going to create another code here.

66
00:05:11,390 --> 00:05:11,690
Here.

67
00:05:11,690 --> 00:05:17,300
We're going to let's make let's comment this out and make new here.

68
00:05:17,600 --> 00:05:24,050
So here, character C and hello.

69
00:05:26,370 --> 00:05:36,480
And here character pointer constant CP one C here and we're going to add comments after we completed

70
00:05:36,480 --> 00:05:37,410
our code here.

71
00:05:38,100 --> 00:05:38,910
Here.

72
00:05:40,160 --> 00:05:43,010
And cost character PTC.

73
00:05:45,810 --> 00:05:47,050
And Constcast.

74
00:05:47,070 --> 00:05:49,350
We're going to use Constcast here.

75
00:05:50,220 --> 00:05:51,930
Constcast.

76
00:05:53,940 --> 00:05:55,620
Const character.

77
00:05:58,020 --> 00:06:00,000
And cp1.

78
00:06:03,550 --> 00:06:06,160
And here, PTC Plus.

79
00:06:06,160 --> 00:06:06,850
Plus.

80
00:06:07,980 --> 00:06:13,370
And after that character comes to const char const.

81
00:06:13,410 --> 00:06:16,260
Cast and character.

82
00:06:16,290 --> 00:06:25,320
Const here and p, t, c and lastly here CP to.

83
00:06:26,160 --> 00:06:26,670
A.

84
00:06:28,840 --> 00:06:29,650
Here.

85
00:06:29,660 --> 00:06:30,580
So.

86
00:06:31,400 --> 00:06:37,250
You can make a point at constant change it or remove it by using the casts here.

87
00:06:37,250 --> 00:06:44,990
And this code here does some fairly pointless changing around the const keyword to prove the point.

88
00:06:45,170 --> 00:06:49,430
So the pointers cp1 here.

89
00:06:49,460 --> 00:06:54,350
Cp1 and CP2.

90
00:06:55,610 --> 00:07:03,020
Can be used to change the memory they point to, but once assigned, neither can point to other memory

91
00:07:03,020 --> 00:07:03,470
here.

92
00:07:03,470 --> 00:07:13,310
So the first const cast here, as you can see, const cast here casts away the const ness to a pointer

93
00:07:13,310 --> 00:07:19,530
that can be changed to point to other memory here, but cannot be used to alter that memory.

94
00:07:19,550 --> 00:07:23,320
So memory in this case, it's a PTC here.

95
00:07:23,330 --> 00:07:34,850
So the second const cast casts away the constants of PTC here so that the memory can be changed through

96
00:07:34,850 --> 00:07:37,070
the pointer CP to.
