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