1 00:00:00,840 --> 00:00:04,560 Reference types, stored memory addresses of the objects. 2 00:00:04,560 --> 00:00:11,310 So these types enable efficient programming and many elegant design patterns feature them. 3 00:00:11,400 --> 00:00:19,140 So in this lecture, I will discuss the two kinds of reference types, the pointers and the references. 4 00:00:19,140 --> 00:00:30,960 I will also discuss this, this keyword keyword here and auto auto keyword along the way. 5 00:00:31,110 --> 00:00:33,330 So let's get started by the pointers. 6 00:00:33,330 --> 00:00:34,920 So pointers. 7 00:00:36,590 --> 00:00:42,110 Are the fundamental mechanism used to refer to memory addresses. 8 00:00:42,500 --> 00:00:50,810 So pointers encode both pieces of information required to interact with another object. 9 00:00:50,810 --> 00:00:56,410 So that is the object address and the object type. 10 00:00:56,420 --> 00:01:03,890 So you can declare a pointer by type by appending an asterisk to the pointer to type. 11 00:01:03,980 --> 00:01:04,610 Here. 12 00:01:04,870 --> 00:01:07,430 Here, for example, my p. 13 00:01:07,430 --> 00:01:07,750 T. 14 00:01:07,760 --> 00:01:08,240 R. 15 00:01:08,510 --> 00:01:14,580 So the format specified for the pointer is this p here. 16 00:01:14,600 --> 00:01:22,880 So for example, to print a value in my TR, you could use this kind of code here. 17 00:01:22,880 --> 00:01:30,890 So the value of my TR, the value of my Peter is p. 18 00:01:30,980 --> 00:01:36,770 This is a format specified for pointer here and my p t are here. 19 00:01:36,890 --> 00:01:38,870 And let's run this here. 20 00:01:38,870 --> 00:01:44,630 And as you can see here, the value of my TR is zeros here. 21 00:01:44,630 --> 00:01:51,890 So the pointers are very low level objects, although they play a central role in most C programs. 22 00:01:51,890 --> 00:02:00,140 So C++ offers higher level, sometimes more efficient constructs that obviate the need to deal with 23 00:02:00,140 --> 00:02:02,810 the memory addresses directly. 24 00:02:02,810 --> 00:02:10,610 So monthlies pointers are foundational concepts that you will know that come across in your system. 25 00:02:10,610 --> 00:02:12,350 Programming travels. 26 00:02:12,950 --> 00:02:22,160 So in this section of our course, you will learn how to find the address of an object and how to assign 27 00:02:22,160 --> 00:02:24,700 the result to a pointer variable. 28 00:02:24,710 --> 00:02:31,400 So you will also learn how to perform the opposite operation, which is called the DE referencing. 29 00:02:31,400 --> 00:02:40,250 So the reference means given a pointer, you can obtain the object residing at the corresponding address 30 00:02:40,460 --> 00:02:42,770 so you will know more about race. 31 00:02:42,770 --> 00:02:50,690 So the simplest construct for measuring an object collection as well as how arrays relate to pointers. 32 00:02:50,690 --> 00:02:56,520 So as low level constructs, arrays and pointers are relatively dangerous. 33 00:02:56,540 --> 00:03:04,260 So you will learn about what can go wrong when pointer and arrays based programs go angry. 34 00:03:04,310 --> 00:03:08,720 So this lecture introduced two special kinds of pointers. 35 00:03:09,710 --> 00:03:23,180 The first is void pointers and the first is void pointers and STD STD byte pointers. 36 00:03:23,900 --> 00:03:26,900 So these are very useful, useful types. 37 00:03:27,020 --> 00:03:34,070 They have some special behaviors that you will need to keep in mind. 38 00:03:34,100 --> 00:03:44,660 Additionally, you will learn how to encode empty pointers with new p tr and how to use in boolean expressions 39 00:03:44,660 --> 00:03:48,260 to determine whether they are empty or not. 40 00:03:49,100 --> 00:03:56,360 So let's get started by addressing variables in C++ pointers so you can obtain the address of variables 41 00:03:56,360 --> 00:03:59,720 by pretending the address of operator. 42 00:03:59,750 --> 00:04:01,190 Actually, I want to note that. 43 00:04:01,190 --> 00:04:08,710 So you will keep in mind that operator operator and operand names in this programming languages. 44 00:04:08,720 --> 00:04:12,710 So this is the address of operator. 45 00:04:12,920 --> 00:04:16,610 Address of operator. 46 00:04:17,060 --> 00:04:28,640 So you might want to use this operator to initialize the pointer so it points to the corresponding variable. 47 00:04:28,670 --> 00:04:33,530 Such programming requirements arise very often in operating system programming. 48 00:04:33,530 --> 00:04:43,040 So for example, major operating system such as Windows, Linux and Free BSD have interfaces that use 49 00:04:43,040 --> 00:04:45,260 pointers here heavily. 50 00:04:46,010 --> 00:04:53,120 So now let's get to the practice practical programming in our course. 51 00:04:53,420 --> 00:05:02,990 So integer my pointer here I will all just for example, my variable here my variable. 52 00:05:03,920 --> 00:05:13,840 So here we will create my variable with this, which I will explain our course later as I do always. 53 00:05:13,850 --> 00:05:17,210 So my variable here. 54 00:05:24,410 --> 00:05:26,150 Your my variable. 55 00:05:26,750 --> 00:05:28,460 Uh, the integer. 56 00:05:30,050 --> 00:05:32,450 My variable address. 57 00:05:36,700 --> 00:05:38,350 My variable. 58 00:05:40,540 --> 00:05:41,970 And then print off. 59 00:05:49,440 --> 00:05:50,030 Yes. 60 00:05:53,020 --> 00:05:54,130 New line. 61 00:05:55,840 --> 00:05:58,570 My variable address. 62 00:06:03,160 --> 00:06:03,730 Here. 63 00:06:05,500 --> 00:06:09,880 So now I will tell you what. 64 00:06:11,550 --> 00:06:21,330 These codes are so v Firstly, you declare that integer my variable and print its value. 65 00:06:21,840 --> 00:06:29,890 So then you declare a pointer called my variable address to that integers address. 66 00:06:29,910 --> 00:06:33,600 As you can see here, we use the address of operator. 67 00:06:34,680 --> 00:06:45,290 So notice that the asset square presents the pointer and ampersand pretends the my variable here. 68 00:06:45,300 --> 00:06:55,560 So finally you point to the pointer to the screen here to reveal the my variable address. 69 00:06:56,380 --> 00:06:57,700 Let's print this out. 70 00:06:58,180 --> 00:07:03,040 And as you can see here, we got the mind variable equal to zero. 71 00:07:03,160 --> 00:07:07,210 And my variable address is this here. 72 00:07:07,240 --> 00:07:16,720 This is the this is where my variable variable resides and lives in our memory, random access memory. 73 00:07:17,890 --> 00:07:23,610 So your output should have an identical value, as you can see here. 74 00:07:23,620 --> 00:07:30,190 But my variable address should be different each time, as you can see here. 75 00:07:30,550 --> 00:07:38,500 So this variation is due to the address space layout randomization, which is a security feature that 76 00:07:38,500 --> 00:07:44,830 scrambles the base address of important memory regions to hamper exploitation.