1
00:00:01,520 --> 00:00:07,240
Pointers provide a lot of flexibility, but this flexibility comes at safety cost.

2
00:00:07,250 --> 00:00:13,580
So if you don't need the flexibility or receipt ability a nullptr.

3
00:00:13,710 --> 00:00:16,880
References are the go to reference type.

4
00:00:16,880 --> 00:00:21,330
So let's drive home to the point that references cannot be reseated.

5
00:00:21,350 --> 00:00:28,550
So here we're going to initialize an integer reference in this lecture and then we will attempt to reseat

6
00:00:28,580 --> 00:00:31,070
it with the new value.

7
00:00:31,610 --> 00:00:35,360
So as always, we have to use the include.

8
00:00:35,390 --> 00:00:40,730
We will use the library, CS uh, studio here and.

9
00:00:41,830 --> 00:00:46,930
Then we're going to create the original variable and assign to 100.

10
00:00:47,110 --> 00:00:56,350
And if you like, have the problem understanding this code, which as I as I always do, I will explain

11
00:00:56,350 --> 00:00:58,300
after when we write the code.

12
00:00:58,480 --> 00:01:09,160
This is ampersand here, original href here, and we're going to assign it to original original here.

13
00:01:09,250 --> 00:01:11,530
And then we will print that.

14
00:01:12,250 --> 00:01:17,310
So remember, we included this the system library.

15
00:01:17,320 --> 00:01:17,980
That's why.

16
00:01:18,010 --> 00:01:21,130
Because we need to use the printf here.

17
00:01:21,280 --> 00:01:22,420
So.

18
00:01:26,490 --> 00:01:27,150
Here.

19
00:01:27,180 --> 00:01:35,730
As you can see here, we do no longer have the function print F, So that's why we included this print,

20
00:01:36,150 --> 00:01:39,660
this studio, um, library here.

21
00:01:39,660 --> 00:01:41,580
So include it again.

22
00:01:43,280 --> 00:01:43,850
Here.

23
00:01:43,850 --> 00:01:47,270
And as you can see, our printf function returns.

24
00:01:47,310 --> 00:01:49,880
So original here?

25
00:01:50,720 --> 00:01:51,260
Yes.

26
00:01:52,160 --> 00:01:53,470
Original here.

27
00:01:53,480 --> 00:01:53,930
The.

28
00:01:57,190 --> 00:02:01,540
And then we're going to print the original value.

29
00:02:01,540 --> 00:02:06,010
And then let's add another print function here and reference.

30
00:02:06,870 --> 00:02:07,290
Here.

31
00:02:12,770 --> 00:02:13,400
Here.

32
00:02:15,680 --> 00:02:16,670
And.

33
00:02:19,460 --> 00:02:22,540
Original dot reference, as you can see here.

34
00:02:22,550 --> 00:02:25,460
And then we're going to create a new value.

35
00:02:25,880 --> 00:02:28,580
Named new value and assign it to 100.

36
00:02:30,490 --> 00:02:36,240
Integer new value is assigned to 200 and original ref.

37
00:02:36,250 --> 00:02:38,350
We will use this original ref here.

38
00:02:38,800 --> 00:02:42,850
Original ref equals new value.

39
00:02:42,940 --> 00:02:46,590
And then we're going to print again this here.

40
00:02:46,600 --> 00:02:52,540
As you can see here, we're going to firstly, we're going to print the original, then new value.

41
00:02:52,540 --> 00:02:56,590
And then lastly, we're going to print the reference variable here.

42
00:02:56,620 --> 00:02:58,780
The first is original here.

43
00:03:02,540 --> 00:03:03,560
We three.

44
00:03:04,990 --> 00:03:07,150
We're going to pass this original here.

45
00:03:09,350 --> 00:03:12,140
Then we're going to print the original ref.

46
00:03:17,010 --> 00:03:18,420
Or new value here.

47
00:03:32,350 --> 00:03:34,150
And lastly, we're going to print the reference.

48
00:03:35,970 --> 00:03:36,300
Here.

49
00:03:38,790 --> 00:03:39,390
Reference.

50
00:03:39,390 --> 00:03:40,020
So.

51
00:03:40,020 --> 00:03:41,100
And then we're going to.

52
00:03:41,640 --> 00:03:43,650
Here, let me write it.

53
00:03:43,710 --> 00:03:44,190
Okay.

54
00:03:44,520 --> 00:03:45,960
Ref Original referee.

55
00:03:46,290 --> 00:03:47,790
So let's run our code.

56
00:03:51,330 --> 00:03:53,220
And that's our output here.

57
00:03:53,220 --> 00:04:05,250
So now the program here initializes initializes an integer called original and 200 here, as you can

58
00:04:05,250 --> 00:04:05,520
see.

59
00:04:05,640 --> 00:04:12,510
Then it declares a reference to original called original ref here, as you can see here.

60
00:04:12,510 --> 00:04:21,120
So from this point on, the original ref will always refer to original here, as you can see here.

61
00:04:21,120 --> 00:04:28,200
So this is illustrated by printing the value of original here.

62
00:04:30,420 --> 00:04:33,690
And the value of refer to type original ref.

63
00:04:34,230 --> 00:04:37,800
So as you can see here, we got the 100 here.

64
00:04:38,010 --> 00:04:48,420
Then you initialize another integer called new value to 200 and then assign original to it.

65
00:04:49,230 --> 00:04:50,400
As you can see here.

66
00:04:50,700 --> 00:04:51,630
So.

67
00:04:53,060 --> 00:04:53,870
Here.

68
00:04:54,530 --> 00:05:00,530
Read it carefully that the assignment here doesn't recede.

69
00:05:00,560 --> 00:05:01,760
Original ref.

70
00:05:01,940 --> 00:05:05,510
So that is points to new value.

71
00:05:05,810 --> 00:05:12,320
Rather, it assigns the value of new value to the object it points to.

72
00:05:12,350 --> 00:05:14,280
That is the original.

73
00:05:14,300 --> 00:05:24,290
So the upshot is that all of these variables original original ref and new value evaluate to 100 after

74
00:05:24,290 --> 00:05:25,640
this code here.
