1 00:00:00,120 --> 00:00:03,640 So in this video, I'm going to be talking about the sectors and union and things saw. 2 00:00:04,200 --> 00:00:10,650 So this move is very important for the upcoming videos because will be creating the structures and pricing 3 00:00:10,650 --> 00:00:17,310 them to the arguments and also will be receiving a pointer to distract us and then we'll be moving over 4 00:00:17,310 --> 00:00:20,310 through this are the structures. 5 00:00:20,730 --> 00:00:26,700 So the structures are so similar to the classes, but these are like normal value types. 6 00:00:28,600 --> 00:00:32,020 So you can create a structure and it's a public structure. 7 00:00:34,060 --> 00:00:43,270 So test either structure and here we can have the structure members so that it's a public entirely and 8 00:00:43,270 --> 00:00:48,130 public in called public string name. 9 00:00:48,130 --> 00:00:54,430 So these three are the members and you you should not initialize these values in this structure. 10 00:00:54,430 --> 00:00:56,830 So this is like a blueprint for this structure. 11 00:00:57,640 --> 00:00:59,050 Now, what we're going to do is. 12 00:01:05,940 --> 00:01:08,560 We are going to create the object for this. 13 00:01:08,560 --> 00:01:15,030 So it's not really like object to a structure or transition. 14 00:01:16,490 --> 00:01:22,790 So let's test B so we can declare like this and we can also declare like this new test. 15 00:01:24,240 --> 00:01:27,690 Similar to degrading objects from the classes. 16 00:01:28,770 --> 00:01:32,640 Now how to access these members is using the date operator debug. 17 00:01:33,090 --> 00:01:39,410 So here you can see we have these blue colour members called ID and. 18 00:01:40,530 --> 00:01:42,630 So you can see called I.D. a name. 19 00:01:43,470 --> 00:01:47,340 So we can put into these also we can assign these by default. 20 00:01:47,340 --> 00:01:49,170 The values will be set to 21 00:01:51,900 --> 00:01:52,440 zero. 22 00:01:54,330 --> 00:01:57,630 So if I go and so. 23 00:01:59,180 --> 00:02:00,110 One, two, three, four. 24 00:02:01,010 --> 00:02:02,990 And I want to print this derogatorily. 25 00:02:04,400 --> 00:02:08,790 Let's go and print this and can see the value of I.D.. 26 00:02:15,510 --> 00:02:21,210 So before initialization, we have this, uh, before assignment, we have this gyro, and after that 27 00:02:21,210 --> 00:02:21,750 we have one. 28 00:02:27,480 --> 00:02:30,000 And the next thing is we need to define the size. 29 00:02:30,300 --> 00:02:33,660 So you need to import this are and then go to drop services. 30 00:02:34,110 --> 00:02:38,670 And here we have martial or not size of. 31 00:02:39,900 --> 00:02:44,520 And here we need to parse the type of the data you want to get the size of. 32 00:02:45,090 --> 00:02:47,880 So I want to see a type of test. 33 00:02:50,670 --> 00:02:55,080 So I want to get the destructor things. 34 00:02:55,650 --> 00:03:02,220 So the integer takes four bytes and next integer takes four bytes and the string is a pointer, so it 35 00:03:02,220 --> 00:03:03,750 takes for weights further. 36 00:03:03,750 --> 00:03:04,800 Ruby provides. 37 00:03:06,050 --> 00:03:09,050 So if I go and print this. 38 00:03:14,020 --> 00:03:16,510 And here you can see those sizes for bites. 39 00:03:18,670 --> 00:03:25,240 Also the difference between the structure and union is the memory allocation will concede better rates 40 00:03:25,570 --> 00:03:31,060 and in the union the whatever has the maximum says. 41 00:03:31,630 --> 00:03:34,630 The whole union gets that same size. 42 00:03:35,140 --> 00:03:44,230 So in the sector we have this four bites and the four bites and the four bites of point. 43 00:03:44,260 --> 00:03:46,670 So we have this debate. 44 00:03:46,990 --> 00:03:48,220 So you can simply add them. 45 00:03:48,220 --> 00:03:52,000 And the size of the sector is simply additional these sizes. 46 00:03:52,390 --> 00:03:59,590 But in union, the maximum size, let's say if this is a double takes, it may take less. 47 00:04:00,040 --> 00:04:06,550 And the whole, uh, union gets the same, uh. 48 00:04:07,560 --> 00:04:08,040 Memory. 49 00:04:09,300 --> 00:04:11,730 Somewhere between union rhetoric. 50 00:04:11,730 --> 00:04:12,360 This video. 51 00:04:13,800 --> 00:04:18,390 And you can see this is identified the public you want. 52 00:04:18,540 --> 00:04:22,730 You can either declare a member as private. 53 00:04:23,990 --> 00:04:28,230 Private bring secret key. 54 00:04:29,350 --> 00:04:34,750 Now what happens is you cannot access the private members of this any structure. 55 00:04:35,350 --> 00:04:37,600 If I go and Peter. 56 00:04:40,850 --> 00:04:46,670 Secretary and European TV have no such section of the secret search warrant. 57 00:04:46,670 --> 00:04:47,330 But this. 58 00:04:48,170 --> 00:04:48,710 And. 59 00:04:49,870 --> 00:04:50,890 We got some address. 60 00:04:51,340 --> 00:04:55,300 So the security's inaccessible due to its production level. 61 00:04:55,310 --> 00:04:59,650 So what we need to do is we need to convert that to public order. 62 00:04:59,650 --> 00:05:04,210 We can also declare and their function that can set this value. 63 00:05:04,660 --> 00:05:13,660 So generally, uh, uh, this method uh like public acquired set. 64 00:05:16,050 --> 00:05:18,000 It's a secret, said secret. 65 00:05:18,300 --> 00:05:24,930 So these methods will be used to set the private members of this structure without knowing the value 66 00:05:24,930 --> 00:05:28,440 of this, without accessing this private member's. 67 00:05:31,330 --> 00:05:37,740 So this spring he began to secret keys to keep. 68 00:05:38,290 --> 00:05:42,250 So this mantra sets the value of this secret. 69 00:05:42,640 --> 00:05:43,540 And that's what we can write. 70 00:05:43,540 --> 00:05:45,580 Another matter that is public. 71 00:05:45,580 --> 00:05:47,920 Why get secret? 72 00:05:50,180 --> 00:05:52,490 And return secret key. 73 00:05:59,080 --> 00:06:02,770 So know how to set the security you need to use this function. 74 00:06:02,960 --> 00:06:06,670 Peter, set secret of you to buy this drink. 75 00:06:07,150 --> 00:06:08,070 So that's, uh. 76 00:06:08,350 --> 00:06:10,750 This is very secret key. 77 00:06:12,610 --> 00:06:18,610 And how to get the secret key using the dark secret. 78 00:06:26,370 --> 00:06:26,670 Okay. 79 00:06:26,670 --> 00:06:27,210 Sorry, sorry. 80 00:06:28,260 --> 00:06:29,760 The string is written down. 81 00:06:30,750 --> 00:06:35,520 So if you run this and here again, see, we got the contents of this secret to keep. 82 00:06:37,080 --> 00:06:39,420 And another way is using the catterson in. 83 00:06:40,230 --> 00:06:44,400 So this is a these are like the properties of this member. 84 00:06:44,760 --> 00:06:47,310 So what we can do is we can simply do it. 85 00:06:47,340 --> 00:06:48,810 These are two functions. 86 00:06:49,710 --> 00:06:51,570 I'm going to say a public. 87 00:06:54,590 --> 00:06:56,450 That's a secret. 88 00:07:00,590 --> 00:07:03,200 And I want to say get. 89 00:07:20,550 --> 00:07:21,720 Return secret key. 90 00:07:24,220 --> 00:07:30,120 And I can also say set and secret keys equals to you. 91 00:07:31,890 --> 00:07:32,730 So it's good. 92 00:07:32,760 --> 00:07:35,190 And so we got some errors. 93 00:07:47,520 --> 00:07:50,040 Now what I can do is build this. 94 00:07:50,310 --> 00:07:52,800 So whenever I set out secret. 95 00:07:55,530 --> 00:07:57,530 Easy calls to read. 96 00:07:57,630 --> 00:07:58,680 Say hello. 97 00:08:01,040 --> 00:08:01,490 Well. 98 00:08:04,200 --> 00:08:07,140 And now I can just print this this secret. 99 00:08:08,310 --> 00:08:13,140 So whenever we are assigning a value, the value will be assigned to this secret key. 100 00:08:14,430 --> 00:08:18,600 Whenever we are going to print this, the value will be automatically returned. 101 00:08:18,810 --> 00:08:20,050 So let's turn this. 102 00:08:20,070 --> 00:08:22,200 And here we can see the string. 103 00:08:22,440 --> 00:08:30,810 So you can access the secret that is simply not a member, but it will perform the operations on this 104 00:08:30,810 --> 00:08:31,690 private member. 105 00:08:31,720 --> 00:08:32,520 Secret key. 106 00:08:33,670 --> 00:08:38,350 And you can also create a constructors for this. 107 00:08:38,560 --> 00:08:43,540 So the constructor will automatically invoke whenever the object is created. 108 00:08:44,530 --> 00:08:50,870 But the drawback of this constructor initiative is all of these values. 109 00:08:51,770 --> 00:08:56,980 You need to have one constructor that initializes all of these member values. 110 00:08:57,650 --> 00:08:58,960 They get the object. 111 00:08:58,960 --> 00:09:01,880 So it's for this activity. 112 00:09:03,730 --> 00:09:08,050 I think it's you use only constructor and you have the new. 113 00:09:09,930 --> 00:09:13,800 And also I want to discuss this earlier. 114 00:09:13,890 --> 00:09:15,690 That is real. 115 00:09:16,890 --> 00:09:18,750 Hopefully they'll kind it out. 116 00:09:19,080 --> 00:09:23,580 And here you can see there are three kinds Expedia, sequential and auto. 117 00:09:23,850 --> 00:09:24,870 So it is exquisite. 118 00:09:24,870 --> 00:09:28,460 You use it for the unions and sequential use for sectors. 119 00:09:28,950 --> 00:09:33,120 So the sequential run over the sector will be exactly as it is. 120 00:09:35,950 --> 00:09:38,980 Very opposite this structure in some other function. 121 00:09:39,310 --> 00:09:45,070 So the members of this functions of the structure will be exactly in the order. 122 00:09:45,280 --> 00:09:50,180 So the first one will be idea, and second and third one will be the secret key. 123 00:09:50,830 --> 00:09:55,210 So there's this one get interchanged when you put this real control sequential. 124 00:09:58,370 --> 00:09:59,260 Now it's different. 125 00:09:59,270 --> 00:10:01,130 And I've got a union. 126 00:10:04,260 --> 00:10:04,820 For this. 127 00:10:05,210 --> 00:10:05,700 They are. 128 00:10:10,120 --> 00:10:12,400 Priorities explicit. 129 00:10:14,110 --> 00:10:22,990 You don't require any union keyword, the same struct you wrote to use it for, uh, union so that my 130 00:10:24,040 --> 00:10:24,640 union. 131 00:10:26,890 --> 00:10:30,150 And now we need to it to our. 132 00:10:32,300 --> 00:10:33,560 The girl to where it was. 133 00:10:34,820 --> 00:10:35,570 Public. 134 00:10:36,960 --> 00:10:37,350 In. 135 00:10:44,170 --> 00:10:44,980 Rule number. 136 00:11:04,470 --> 00:11:12,250 And really we need to declare a field offset of the offset where this variable starts. 137 00:11:12,270 --> 00:11:19,140 So if I said zero, then this would be the starting position sort of to declare another variable in. 138 00:11:21,040 --> 00:11:21,650 Agreed. 139 00:11:22,560 --> 00:11:24,180 And let me read to. 140 00:11:28,180 --> 00:11:29,620 Veered off set of zero. 141 00:11:31,230 --> 00:11:35,490 So the thing is, both start at the same location, same opposite. 142 00:11:35,880 --> 00:11:43,080 So that means if you assign any value to this or in a model and if you build up this grade, then this 143 00:11:43,560 --> 00:11:49,650 value will be printed because they share both the memory location and at the same offset. 144 00:11:49,800 --> 00:11:51,530 So that create the. 145 00:11:55,770 --> 00:11:57,190 So the name is my union. 146 00:11:57,250 --> 00:11:58,230 Okay, so. 147 00:12:00,070 --> 00:12:03,670 My union and musical store knew my union. 148 00:12:05,830 --> 00:12:11,390 And so saying that raw numbers equals to that fight. 149 00:12:14,410 --> 00:12:16,990 Now let's go and put this in the raw number. 150 00:12:18,190 --> 00:12:20,200 We're just pretending it's where you know. 151 00:12:20,710 --> 00:12:21,970 And here you can see the fight. 152 00:12:22,690 --> 00:12:25,420 Now let's go and turn this to grade. 153 00:12:28,210 --> 00:12:35,380 Now here you can see we got the same value because the the memory allocated is the same the four bytes. 154 00:12:35,950 --> 00:12:36,520 That's also 155 00:12:39,310 --> 00:12:40,510 the value of. 156 00:12:41,910 --> 00:12:42,690 The size. 157 00:12:55,900 --> 00:12:59,950 And we can see we got only four words for that to reduce. 158 00:13:00,280 --> 00:13:02,890 No, let me go and change this field out to four. 159 00:13:04,000 --> 00:13:09,790 So if you started the four so program that my union pressed for. 160 00:13:11,410 --> 00:13:22,410 And if I go and assign a different number to the grade and also print the wrong number as well the number. 161 00:13:22,780 --> 00:13:26,170 So we'll be seeing different values for these two variables. 162 00:13:26,710 --> 00:13:35,080 Because of, uh, because of eight bytes, you can see the file, which is the value of row number and 163 00:13:35,080 --> 00:13:36,280 the grade is under. 164 00:13:36,280 --> 00:13:39,610 And the size of this union is gigabytes. 165 00:13:42,220 --> 00:13:45,790 So this is about the basic societies and unions. 166 00:13:46,330 --> 00:13:48,880 We're also seeing the national sectors now. 167 00:13:49,030 --> 00:13:53,680 So we can also include this union in my centre. 168 00:13:54,220 --> 00:13:57,940 So all I need to do is I can say public. 169 00:14:00,600 --> 00:14:05,160 So that type of this variable I want to create, that is of the day my union. 170 00:14:05,340 --> 00:14:08,630 My union that I'm on. 171 00:14:08,970 --> 00:14:09,690 I am to. 172 00:14:14,530 --> 00:14:17,650 Now, let me comment on this. 173 00:14:23,670 --> 00:14:34,200 Now when I created this tea, I can simply access the members of this union by using be dot young to 174 00:14:34,200 --> 00:14:36,260 dot this member. 175 00:14:37,080 --> 00:14:42,790 B .2.0 number is equal to 69. 176 00:14:43,350 --> 00:14:47,100 And let's go and put in this beta, a computer or a number. 177 00:14:48,270 --> 00:14:54,450 Let's go and run this and you can see the values X and also let's print out the whole size. 178 00:14:54,600 --> 00:14:56,640 So we are printing the size of this. 179 00:14:57,600 --> 00:14:59,310 So down for whites. 180 00:14:59,310 --> 00:15:03,180 For whites and this is for. 181 00:15:04,020 --> 00:15:07,110 And this should be it, I guess. 182 00:15:09,770 --> 00:15:11,660 So total will be 20. 183 00:15:12,710 --> 00:15:16,400 So we got these 20 points and it's. 184 00:15:18,060 --> 00:15:18,810 Jane this. 185 00:15:18,810 --> 00:15:20,640 And now we get only 16. 186 00:15:25,950 --> 00:15:30,120 So this is all about the cities and unions in this region.