1 00:00:03,730 --> 00:00:06,360 Signs we are covering the use of variables. 2 00:00:06,370 --> 00:00:12,550 It's worth explaining the syntax used to define pointers and the race because there are some potential 3 00:00:12,550 --> 00:00:13,360 pitfalls. 4 00:00:13,450 --> 00:00:20,380 So working with the memory arrays and pointers covers in the in next lectures in more detail. 5 00:00:20,380 --> 00:00:24,730 So we will just introduce the syntax so that you are familiar with it. 6 00:00:25,150 --> 00:00:30,370 So in C++ you will access memory use a typed point. 7 00:00:31,060 --> 00:00:37,560 So the type indicates the type of the data that's held in the memory that is pointed to. 8 00:00:37,630 --> 00:00:44,620 So if the pointer is an four byte integer pointer, it will point to four bytes that can be used as 9 00:00:44,620 --> 00:00:45,280 an integer. 10 00:00:45,580 --> 00:00:52,900 If the integer pointer is incremented, then it will point to the next four bytes, which can be used 11 00:00:52,900 --> 00:00:54,550 as an integer. 12 00:00:54,790 --> 00:01:00,160 So in C++, pointers are declared using the asterisk here. 13 00:01:00,160 --> 00:01:01,090 Asterisk. 14 00:01:03,050 --> 00:01:10,310 So using this asterisk symbol and you access a memory others with this and opera. 15 00:01:10,970 --> 00:01:12,710 So let's create a pointer. 16 00:01:12,740 --> 00:01:24,770 P here integer E, 52 and P equals and operator and the symbol here. 17 00:01:24,860 --> 00:01:28,610 And so now I want to explain uncomment these lines. 18 00:01:28,940 --> 00:01:36,470 So you can when you download these codes, you got the understanding of what these lines means. 19 00:01:37,320 --> 00:01:47,160 So the first line declares a variable P, which will be used will be used to hold the memory address 20 00:01:47,160 --> 00:01:48,960 of an integer. 21 00:01:50,190 --> 00:01:53,250 So the next one here. 22 00:01:55,870 --> 00:02:07,990 The second line declares an integer, declare squares and an integer and signs value. 23 00:02:08,590 --> 00:02:16,090 As you remember, this is just an usual, usual thing that how we declare the integer values here. 24 00:02:16,300 --> 00:02:20,380 Nothing strange here but new here for for us. 25 00:02:20,380 --> 00:02:22,270 Here and here. 26 00:02:22,270 --> 00:02:25,060 As you can see, we used the end operator. 27 00:02:25,090 --> 00:02:27,910 So this and the third line. 28 00:02:27,910 --> 00:02:32,980 The signs of value assigns a value. 29 00:02:34,210 --> 00:02:35,560 Assigns a value. 30 00:02:35,560 --> 00:02:44,380 So this assigns a value to the pointer P here. 31 00:02:45,480 --> 00:02:48,030 To be the address. 32 00:02:48,970 --> 00:02:51,280 Of the integer. 33 00:02:52,190 --> 00:02:52,910 Valuable. 34 00:02:55,460 --> 00:03:02,600 So it's important to stress that the value of P is not 52. 35 00:03:03,440 --> 00:03:07,130 If the memory others where the value of 52 is stored. 36 00:03:08,320 --> 00:03:14,950 So not how the declaration has the asterisk here on the variable name. 37 00:03:14,950 --> 00:03:21,730 This is the common convention that the reason is that if you declare several variables on in one statement, 38 00:03:22,600 --> 00:03:26,790 the asterisk here applies only to the immediate variables. 39 00:03:26,800 --> 00:03:34,660 So for example, let's create an integer integer P one, p2p3 here. 40 00:03:35,320 --> 00:03:40,570 So as you can see here, this is the example of this is a common convention. 41 00:03:40,810 --> 00:03:46,960 The reason is that if you declare several variables in one statements, this asterisk applies only to 42 00:03:46,960 --> 00:03:49,900 the media immediate variable. 43 00:03:50,290 --> 00:03:55,960 And let's create another example of the declaring pointer types here. 44 00:03:55,960 --> 00:04:04,780 So this looks like you're declaring here as you as you can see this make here integer, this will look 45 00:04:04,780 --> 00:04:08,430 like you are declaring two integer pointers. 46 00:04:08,440 --> 00:04:10,810 However, this line does not do this here. 47 00:04:12,160 --> 00:04:14,110 Integer P one. 48 00:04:15,130 --> 00:04:16,990 An integer feature. 49 00:04:17,470 --> 00:04:22,390 Actually, we did app1 integer SW one. 50 00:04:23,630 --> 00:04:25,130 Integer as to. 51 00:04:26,190 --> 00:04:26,560 Here. 52 00:04:27,300 --> 00:04:28,230 So. 53 00:04:29,270 --> 00:04:31,430 As you can see here. 54 00:04:33,280 --> 00:04:35,290 This line does not do this. 55 00:04:35,350 --> 00:04:37,240 So we have three pointers here. 56 00:04:37,240 --> 00:04:38,560 Point two types here. 57 00:04:38,740 --> 00:04:46,600 And this line does not do as does this, because the second variable is an integer called P called S 58 00:04:46,600 --> 00:04:55,720 two, and it declares just one pointer called called S one integer pointer here. 59 00:04:56,230 --> 00:05:06,100 And if you wish to declare the two integers in one statement, then you should do as follows. 60 00:05:06,100 --> 00:05:10,240 Here p one and or. 61 00:05:12,660 --> 00:05:14,160 One and. 62 00:05:16,090 --> 00:05:17,620 To to. 63 00:05:18,070 --> 00:05:28,150 So this is the correct one if you want if you want to declare two pointers to 2.8 types here.