1 00:00:00,960 --> 00:00:09,030 The reference operator that the reference operator is a unit operator that accesses the object to which 2 00:00:09,030 --> 00:00:10,440 a pointer refers. 3 00:00:10,470 --> 00:00:12,640 Here, let me take the note here. 4 00:00:12,660 --> 00:00:14,070 The reference. 5 00:00:15,490 --> 00:00:16,660 Operator here. 6 00:00:17,830 --> 00:00:23,620 So this is the inverse operation of the address of operator like the address of operator. 7 00:00:23,650 --> 00:00:27,790 System programmers used the reference operator very often. 8 00:00:27,790 --> 00:00:36,640 So many operating system APIs will return pointers and if you want the access to refer to Albrecht, 9 00:00:36,640 --> 00:00:39,640 you will use the reference operator here. 10 00:00:39,640 --> 00:00:45,940 So unfortunately that the reference operator can cause a lot of notation based confusion for beginners 11 00:00:45,940 --> 00:00:54,040 because the reference operator, the Pointer Declaration and the multiple action all use asterisk. 12 00:00:54,040 --> 00:01:00,790 So remember that you append an asterisk to the. 13 00:01:01,980 --> 00:01:05,640 End of the pointer to type objects type to declare a pointer. 14 00:01:06,270 --> 00:01:12,450 So however you prepend the reference operator and asterisk to pointer. 15 00:01:12,450 --> 00:01:17,700 So like this, for example, my my variable address here. 16 00:01:18,210 --> 00:01:19,170 So. 17 00:01:20,740 --> 00:01:27,190 After excising an object by pretending that the reference operator to a pointer, you can treat a result 18 00:01:27,190 --> 00:01:31,570 like any other object of the pointer to type. 19 00:01:31,570 --> 00:01:42,640 So for example, because the my variable is an integer, you can write the value into my variable using 20 00:01:42,640 --> 00:01:44,800 the my variable address pointer here. 21 00:01:44,800 --> 00:01:54,040 So the syntax is like that, my variable address and here 995. 22 00:01:54,250 --> 00:02:01,000 And as you can see here, we've brought this variable by using a pointer, but we used the reference 23 00:02:01,000 --> 00:02:01,390 operator. 24 00:02:01,390 --> 00:02:04,210 So let's print our variable name. 25 00:02:04,360 --> 00:02:05,530 My variable. 26 00:02:06,680 --> 00:02:07,580 Well here. 27 00:02:07,790 --> 00:02:14,900 Well, let's print out a variable value and decimal and. 28 00:02:15,790 --> 00:02:16,450 Here. 29 00:02:17,830 --> 00:02:18,820 My vegetable. 30 00:02:19,240 --> 00:02:20,590 My vegetable. 31 00:02:22,700 --> 00:02:23,660 And run. 32 00:02:24,050 --> 00:02:27,020 And as you can see here, we assigned. 33 00:02:28,070 --> 00:02:33,350 This variable address using variable address with the reference operator. 34 00:02:33,710 --> 00:02:42,320 So because that the reference pointer that is my variable address appears on the left side of the equal 35 00:02:42,320 --> 00:02:45,650 sign you are writing to the address. 36 00:02:45,650 --> 00:02:47,990 Where gets here? 37 00:02:48,000 --> 00:02:56,900 My variable address is stored, so if the reference pointers appears anywhere except the left side of 38 00:02:56,900 --> 00:03:01,490 an equal sign, you are reading from the address. 39 00:03:01,490 --> 00:03:10,130 So to retrieve the integer pointer to by the my variable address here, you can tack on the reference 40 00:03:10,130 --> 00:03:11,180 operator. 41 00:03:11,270 --> 00:03:18,710 For instance, this code here will print a value stored in the my variable here. 42 00:03:18,740 --> 00:03:20,600 So here. 43 00:03:21,860 --> 00:03:22,910 The simple. 44 00:03:24,000 --> 00:03:26,220 Integer or just an integer here. 45 00:03:26,490 --> 00:03:27,210 The. 46 00:03:29,920 --> 00:03:33,970 And my variable address. 47 00:03:34,820 --> 00:03:37,990 Here and this will take from it. 48 00:03:38,970 --> 00:03:39,480 Here. 49 00:03:43,840 --> 00:03:44,280 Right. 50 00:03:44,590 --> 00:03:51,040 And as you can see here, this cutter turned the same number here. 51 00:03:52,660 --> 00:03:53,650 So. 52 00:03:58,670 --> 00:03:59,610 Q I'm. 53 00:03:59,720 --> 00:04:01,730 I want to get some code. 54 00:04:02,370 --> 00:04:12,990 Some example code that we will make it happen to show how this the reference and address of operators 55 00:04:12,990 --> 00:04:15,540 work in depth in C++. 56 00:04:16,050 --> 00:04:22,080 So let's firstly here we will create the. 57 00:04:23,940 --> 00:04:28,800 Integer my variable here and assign it to zero. 58 00:04:29,550 --> 00:04:31,950 Or let's change a name here. 59 00:04:31,980 --> 00:04:33,090 My car. 60 00:04:34,140 --> 00:04:36,030 Assign it to zero. 61 00:04:37,660 --> 00:04:39,910 Or let's change to my age here. 62 00:04:40,270 --> 00:04:43,810 It was be more appropriate for an integer. 63 00:04:43,810 --> 00:04:45,250 So integer. 64 00:04:45,410 --> 00:04:48,790 This the reference pointer here, as you can see here. 65 00:04:49,840 --> 00:04:50,740 Integer. 66 00:04:52,770 --> 00:04:55,890 My age address. 67 00:04:57,320 --> 00:04:57,760 Here. 68 00:04:57,770 --> 00:05:08,360 So I want to mention that it doesn't matter if you write the this asterisk operator here or just after 69 00:05:08,360 --> 00:05:20,090 the here, because actually it's just the your you can write the both sides but it have to between integer 70 00:05:20,090 --> 00:05:22,460 and the variable name in C++ here. 71 00:05:22,670 --> 00:05:33,350 So I will write in this time I will write here my age address address here and my age. 72 00:05:33,980 --> 00:05:36,080 I will explain all of this codes later. 73 00:05:36,530 --> 00:05:37,310 Printf. 74 00:05:39,080 --> 00:05:39,540 Here. 75 00:05:39,680 --> 00:05:43,640 Value at my age. 76 00:05:43,730 --> 00:05:44,720 Address. 77 00:05:45,620 --> 00:05:50,480 Here and we will print that a new line here. 78 00:05:52,330 --> 00:05:52,990 Will use that. 79 00:05:53,530 --> 00:05:56,470 We will use the assets, the reference operator. 80 00:05:56,470 --> 00:05:58,870 And as you know, this is the address of operator. 81 00:05:59,230 --> 00:06:07,780 We will use both of them in this example code my age address and then print F again. 82 00:06:10,970 --> 00:06:16,070 My age my age address here. 83 00:06:16,100 --> 00:06:23,930 As you know, the format specified for pointer is P and the new line. 84 00:06:25,430 --> 00:06:25,940 Here. 85 00:06:25,970 --> 00:06:34,250 We will write my age address here just and without the reference of other referencing or without the 86 00:06:34,250 --> 00:06:42,530 referencing or others of operator, because this is my address itself is just a pointer type integer 87 00:06:42,530 --> 00:06:43,610 pointer type here. 88 00:06:44,510 --> 00:06:56,030 So then we will assign, we will use the asterisk here and assign it to nine for example, 1019 nine 89 00:06:56,030 --> 00:06:56,480 here. 90 00:06:56,480 --> 00:06:58,310 Ten 129 nine. 91 00:06:59,030 --> 00:07:00,050 And then. 92 00:07:01,200 --> 00:07:02,420 And printf. 93 00:07:02,430 --> 00:07:03,150 Here. 94 00:07:03,420 --> 00:07:04,470 Value. 95 00:07:06,380 --> 00:07:12,080 Well, you add my, uh, my age address here. 96 00:07:12,560 --> 00:07:13,460 Decimal. 97 00:07:14,180 --> 00:07:18,230 As you know, this is an integer format format specified for integer. 98 00:07:18,650 --> 00:07:25,790 And we will use the asterisk, the reference operator, and my my age address. 99 00:07:26,860 --> 00:07:27,640 My age. 100 00:07:27,930 --> 00:07:35,730 As you can see, we can use the my age by itself because in direction requires pointer operant here. 101 00:07:35,740 --> 00:07:37,600 And that's why we will use you. 102 00:07:37,600 --> 00:07:41,660 We will use the integer pointer here and then print F. 103 00:07:41,680 --> 00:07:42,580 Lastly. 104 00:07:44,230 --> 00:07:50,050 Here's my bar address or my age Address. 105 00:07:50,200 --> 00:07:50,770 Sorry. 106 00:07:51,070 --> 00:07:52,960 My age address. 107 00:07:53,260 --> 00:07:53,890 Here. 108 00:07:54,840 --> 00:07:55,970 Pointer type. 109 00:07:57,710 --> 00:07:59,120 Pointer type. 110 00:08:00,280 --> 00:08:00,820 Yeah. 111 00:08:05,080 --> 00:08:05,620 Here. 112 00:08:08,100 --> 00:08:12,840 My age address without any operators. 113 00:08:13,960 --> 00:08:16,660 And let's run our code. 114 00:08:16,930 --> 00:08:21,190 And I will explain all of this in this lecture. 115 00:08:21,730 --> 00:08:22,450 So. 116 00:08:24,270 --> 00:08:29,850 First you initialize the my age to zero. 117 00:08:30,510 --> 00:08:36,870 Then you initialize to the pointer here to the pointer. 118 00:08:38,040 --> 00:08:42,690 My age address to the address of my H here. 119 00:08:42,720 --> 00:08:46,020 So next you print the. 120 00:08:47,840 --> 00:08:50,390 Integer pointed to by address here. 121 00:08:50,390 --> 00:08:57,920 As you can see, we use the asterisk operator here, the reference operator, and we will we will print 122 00:08:57,920 --> 00:09:02,710 the value of the my age address here. 123 00:09:02,720 --> 00:09:14,510 So then we write the value ten, nine, nine, 1009 and nine into the memory, pointed to my age address 124 00:09:14,510 --> 00:09:22,760 and then print the pointed to value here as you can see here and the address again. 125 00:09:22,880 --> 00:09:30,350 So then as you can see here, we this is the pointer to type and this is the address here. 126 00:09:30,920 --> 00:09:39,170 So and as you can see here, firstly my age addresses was equal to zero. 127 00:09:39,920 --> 00:09:40,940 And then. 128 00:09:42,430 --> 00:09:43,630 Uh, here. 129 00:09:45,080 --> 00:09:45,710 The. 130 00:09:46,560 --> 00:09:57,180 Address was same to and after the initialization here or changing the address to changing the variable 131 00:09:57,180 --> 00:10:03,210 of my edge variable to another var here and value here. 132 00:10:03,210 --> 00:10:08,280 And as you can see, we got the same addresses but different values.