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