1 00:00:02,580 --> 00:00:04,590 Using null pointers. 2 00:00:04,590 --> 00:00:10,140 So a pointer could point to anywhere in the memory installed on your computer. 3 00:00:10,140 --> 00:00:16,050 So and an assignment that the reference pointer means that you could potentially write over sensitive 4 00:00:16,050 --> 00:00:24,150 memory used by operating systems so or write to memory used by hardware on your machine. 5 00:00:24,150 --> 00:00:30,960 However, the operating systems will usually give an executable, a specific memory range that it can 6 00:00:30,960 --> 00:00:33,900 access and it tends to access memory. 7 00:00:33,900 --> 00:00:42,060 And if it attempts to access memory out of this range, this it will cause an operating system memory 8 00:00:42,060 --> 00:00:43,800 access violation. 9 00:00:43,800 --> 00:00:53,520 So for this reason you should almost always opt in pointer values using the and operator here or from 10 00:00:53,520 --> 00:00:55,920 a call to an operating system function. 11 00:00:55,920 --> 00:00:59,790 So you should not give a pointer an absolute address. 12 00:00:59,790 --> 00:01:07,570 The only exception to this is the C plus plus constant for invalid memory address nullptr here. 13 00:01:07,570 --> 00:01:09,820 So for example, let's define the pointer here. 14 00:01:10,540 --> 00:01:14,770 Let's define the pointer here and assign it as new. 15 00:01:15,730 --> 00:01:21,130 Here you add the code and integer A and 62. 16 00:01:21,890 --> 00:01:31,220 And then assign P here our a variable a a integer variable here and code here as well. 17 00:01:32,050 --> 00:01:33,970 For example, just an example code. 18 00:01:34,000 --> 00:01:36,250 We won't write it in this lecture here. 19 00:01:36,460 --> 00:01:44,170 So if our nullptr not equals to P, then. 20 00:01:45,350 --> 00:01:47,780 C out STD. 21 00:01:49,430 --> 00:01:50,170 Here. 22 00:01:50,210 --> 00:01:54,050 See out here and. 23 00:01:55,170 --> 00:02:00,810 P with asterisk here and and here. 24 00:02:01,590 --> 00:02:09,750 So this code initializes the pointer pointer p to nullptr. 25 00:02:10,110 --> 00:02:12,530 Here we get an error here and line. 26 00:02:12,540 --> 00:02:13,080 Yes. 27 00:02:13,560 --> 00:02:16,440 So this code initialized p to nullptr. 28 00:02:16,740 --> 00:02:23,490 Later in the code the pointer is initialized to the address of an integer variable. 29 00:02:24,030 --> 00:02:30,450 So still later in the code the pointer is used, but rather than calling it immediately. 30 00:02:30,450 --> 00:02:37,680 So the pointer is first check to ensure that it has been initialized to a non null value. 31 00:02:37,680 --> 00:02:44,430 So the compiler will check to see if you are about to use a variable that has not been initialized. 32 00:02:44,430 --> 00:02:51,270 But if you are writing library code, the compiler will not know whether the colors of your code will 33 00:02:51,270 --> 00:02:53,700 use pointers correctly. 34 00:02:53,700 --> 00:02:59,110 So the type here type of constant nullptr is not an integer. 35 00:02:59,110 --> 00:03:01,510 It is here a STD. 36 00:03:02,940 --> 00:03:13,540 No variables so I'll pointers type can be implicitly converted to this type, so nullptr can be used 37 00:03:13,540 --> 00:03:18,150 to initialize variables of all pointer types.