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