1
00:00:00,830 --> 00:00:05,690
In this lecture you will learn about the references in C plus plus.

2
00:00:05,720 --> 00:00:11,000
References are safer, more convenient versions of pointers.

3
00:00:11,030 --> 00:00:19,730
You declare references with this ampersand declaration here um, appended to the type name.

4
00:00:19,730 --> 00:00:26,380
So references cannot be assigned to null and they cannot be reseated or resigned.

5
00:00:26,390 --> 00:00:31,430
So these characteristics eliminate some bugs endemic to pointers.

6
00:00:31,430 --> 00:00:36,680
So the syntax for dealing in references is much cleaner than for pointers.

7
00:00:36,680 --> 00:00:44,330
So rather than using the member of Pointer and the reference operators, you use references exactly

8
00:00:44,330 --> 00:00:47,600
as if they are of the pointer to type.

9
00:00:47,600 --> 00:00:48,290
So.

10
00:00:49,040 --> 00:00:56,360
Now I want to create some, uh, firstly, we going to create the ad here outside of the main function,

11
00:00:56,390 --> 00:01:02,720
of course we're going to create the void ad year, ad year.

12
00:01:02,720 --> 00:01:11,420
So we will fill this function after creating our struct, which we're going to create a struct here

13
00:01:11,420 --> 00:01:12,590
named the.

14
00:01:13,650 --> 00:01:14,790
World clock.

15
00:01:14,820 --> 00:01:16,980
World clock here.

16
00:01:18,210 --> 00:01:23,220
Or let's make name it for the year here.

17
00:01:23,280 --> 00:01:24,540
World year.

18
00:01:25,290 --> 00:01:33,510
And in this racket, we're going to have the integer type integer variable named year here.

19
00:01:33,660 --> 00:01:39,420
And we're going to use the getter and setter methods to assign this year something.

20
00:01:40,290 --> 00:01:46,170
First, let's assign use getter method here integer.

21
00:01:47,540 --> 00:01:48,650
We will make made.

22
00:01:48,740 --> 00:01:55,430
We made this integer because the getter method, as you know, returns something on it.

23
00:01:55,430 --> 00:01:58,250
So in this case, we're going to return the integer number.

24
00:01:59,250 --> 00:02:00,210
Uh, integer.

25
00:02:00,240 --> 00:02:01,230
Get here.

26
00:02:01,260 --> 00:02:02,130
Here.

27
00:02:02,250 --> 00:02:05,460
And return.

28
00:02:05,460 --> 00:02:07,850
Return here.

29
00:02:08,110 --> 00:02:08,830
Here.

30
00:02:09,480 --> 00:02:12,590
And we're going to use the setter method as well.

31
00:02:12,600 --> 00:02:18,120
The setter method can be just, uh, void in this case.

32
00:02:18,870 --> 00:02:20,370
Uh, set.

33
00:02:20,880 --> 00:02:24,840
Set here and integer.

34
00:02:26,590 --> 00:02:29,080
The temporary year here.

35
00:02:30,140 --> 00:02:30,950
And.

36
00:02:32,820 --> 00:02:36,600
Year equals to year.

37
00:02:42,300 --> 00:02:45,030
And then we're going to let's create an.

38
00:02:46,010 --> 00:02:47,270
This function here.

39
00:02:50,300 --> 00:02:50,960
Here.

40
00:02:51,350 --> 00:02:53,060
So firstly.

41
00:02:54,250 --> 00:03:03,550
We're going to this add parameter will get the struct type name the world year and as a parameter.

42
00:03:03,640 --> 00:03:12,310
So world year this ampersand here and uh, for example my.

43
00:03:13,030 --> 00:03:15,400
For X year here.

44
00:03:16,500 --> 00:03:17,490
And then.

45
00:03:19,140 --> 00:03:20,550
Uh, x here.

46
00:03:20,790 --> 00:03:21,530
X here.

47
00:03:21,540 --> 00:03:23,100
Dot set here.

48
00:03:23,750 --> 00:03:24,190
Here.

49
00:03:24,240 --> 00:03:24,960
And x here.

50
00:03:24,960 --> 00:03:25,830
That.

51
00:03:25,830 --> 00:03:28,710
Get here plus one.

52
00:03:29,190 --> 00:03:33,450
That's because we're going to increment our the year.

53
00:03:34,390 --> 00:03:39,850
Uh, by one, whenever we execute this function here.

54
00:03:39,850 --> 00:03:43,030
And let's come to the main function here.

55
00:03:43,460 --> 00:03:44,440
Uh, here.

56
00:03:44,500 --> 00:03:46,030
My world.

57
00:03:46,420 --> 00:03:46,990
World.

58
00:03:47,020 --> 00:03:47,310
Here.

59
00:03:47,320 --> 00:03:47,650
Here.

60
00:03:47,770 --> 00:03:49,120
World year.

61
00:03:49,240 --> 00:03:50,800
World year.

62
00:03:51,490 --> 00:03:53,680
Um, Earth, for example.

63
00:03:53,680 --> 00:03:56,710
My earth here.

64
00:03:57,670 --> 00:04:00,230
We're going to print something on the screen.

65
00:04:00,440 --> 00:04:01,750
Screen here.

66
00:04:01,750 --> 00:04:06,310
In this case, we're going to print the variable named year.

67
00:04:06,610 --> 00:04:11,430
The year is the year is decimal.

68
00:04:11,440 --> 00:04:19,210
I will explain all of these codes one by one later after we have done this project here in this lecture.

69
00:04:20,350 --> 00:04:21,070
So.

70
00:04:21,790 --> 00:04:23,680
Clock Dot, Get here.

71
00:04:24,810 --> 00:04:29,700
Clock that actually not clock my earth, that gate here.

72
00:04:30,330 --> 00:04:39,450
And after that we're going to call the adhere function and pass my earth as a parameter.

73
00:04:40,180 --> 00:04:45,730
And after that we will print the print this again.

74
00:04:47,710 --> 00:04:48,340
Here.

75
00:04:51,330 --> 00:04:54,120
And let's run our program now.

76
00:04:54,780 --> 00:05:01,710
As you can see here, this returned first to zero and then one which this means our variable incremented

77
00:05:01,710 --> 00:05:02,450
by one.

78
00:05:02,460 --> 00:05:03,630
So.

79
00:05:04,670 --> 00:05:15,740
Uh, so for example, if I want to just return the 2023, in this case, I have to assign my Earth dot

80
00:05:15,800 --> 00:05:25,310
set year 2020 22 and it will increment the year two by one.

81
00:05:25,310 --> 00:05:32,870
So now I want to talk about these codes one by one, what we did in the technical manner of this.

82
00:05:32,870 --> 00:05:38,630
So you the firstly, you declare the world year argument as here.

83
00:05:39,690 --> 00:05:43,320
As a reference using the ampersand.

84
00:05:44,060 --> 00:05:47,240
Rather than asterisk here, as you can see here.

85
00:05:47,270 --> 00:05:56,320
Then within a add year, you use the X year as if it were of the type world year.

86
00:05:56,330 --> 00:06:01,310
So there's no need to use a clumsy dereference and pointer to reference operators.

87
00:06:01,520 --> 00:06:06,380
First, you print the value as a value of year here.

88
00:06:08,200 --> 00:06:16,240
And the next, uh, at the call site, you pass the, uh, my Earth object directly into.

89
00:06:17,290 --> 00:06:18,130
Here.

90
00:06:18,160 --> 00:06:22,510
Add the year and there's no need to take its address.

91
00:06:22,540 --> 00:06:30,310
Finally, you print the value of year again to illustrate that it has incremented.

92
00:06:32,170 --> 00:06:33,490
As you can see here.
