So in this video, I'm going to be talking about the sectors and union and things saw.
So this move is very important for the upcoming videos because will be creating the structures and pricing
them to the arguments and also will be receiving a pointer to distract us and then we'll be moving over
through this are the structures.
So the structures are so similar to the classes, but these are like normal value types.
So you can create a structure and it's a public structure.
So test either structure and here we can have the structure members so that it's a public entirely and
public in called public string name.
So these three are the members and you you should not initialize these values in this structure.
So this is like a blueprint for this structure.
Now, what we're going to do is.
We are going to create the object for this.
So it's not really like object to a structure or transition.
So let's test B so we can declare like this and we can also declare like this new test.
Similar to degrading objects from the classes.
Now how to access these members is using the date operator debug.
So here you can see we have these blue colour members called ID and.
So you can see called I.D. a name.
So we can put into these also we can assign these by default.
The values will be set to
zero.
So if I go and so.
One, two, three, four.
And I want to print this derogatorily.
Let's go and print this and can see the value of I.D..
So before initialization, we have this, uh, before assignment, we have this gyro, and after that
we have one.
And the next thing is we need to define the size.
So you need to import this are and then go to drop services.
And here we have martial or not size of.
And here we need to parse the type of the data you want to get the size of.
So I want to see a type of test.
So I want to get the destructor things.
So the integer takes four bytes and next integer takes four bytes and the string is a pointer, so it
takes for weights further.
Ruby provides.
So if I go and print this.
And here you can see those sizes for bites.
Also the difference between the structure and union is the memory allocation will concede better rates
and in the union the whatever has the maximum says.
The whole union gets that same size.
So in the sector we have this four bites and the four bites and the four bites of point.
So we have this debate.
So you can simply add them.
And the size of the sector is simply additional these sizes.
But in union, the maximum size, let's say if this is a double takes, it may take less.
And the whole, uh, union gets the same, uh.
Memory.
Somewhere between union rhetoric.
This video.
And you can see this is identified the public you want.
You can either declare a member as private.
Private bring secret key.
Now what happens is you cannot access the private members of this any structure.
If I go and Peter.
Secretary and European TV have no such section of the secret search warrant.
But this.
And.
We got some address.
So the security's inaccessible due to its production level.
So what we need to do is we need to convert that to public order.
We can also declare and their function that can set this value.
So generally, uh, uh, this method uh like public acquired set.
It's a secret, said secret.
So these methods will be used to set the private members of this structure without knowing the value
of this, without accessing this private member's.
So this spring he began to secret keys to keep.
So this mantra sets the value of this secret.
And that's what we can write.
Another matter that is public.
Why get secret?
And return secret key.
So know how to set the security you need to use this function.
Peter, set secret of you to buy this drink.
So that's, uh.
This is very secret key.
And how to get the secret key using the dark secret.
Okay.
Sorry, sorry.
The string is written down.
So if you run this and here again, see, we got the contents of this secret to keep.
And another way is using the catterson in.
So this is a these are like the properties of this member.
So what we can do is we can simply do it.
These are two functions.
I'm going to say a public.
That's a secret.
And I want to say get.
Return secret key.
And I can also say set and secret keys equals to you.
So it's good.
And so we got some errors.
Now what I can do is build this.
So whenever I set out secret.
Easy calls to read.
Say hello.
Well.
And now I can just print this this secret.
So whenever we are assigning a value, the value will be assigned to this secret key.
Whenever we are going to print this, the value will be automatically returned.
So let's turn this.
And here we can see the string.
So you can access the secret that is simply not a member, but it will perform the operations on this
private member.
Secret key.
And you can also create a constructors for this.
So the constructor will automatically invoke whenever the object is created.
But the drawback of this constructor initiative is all of these values.
You need to have one constructor that initializes all of these member values.
They get the object.
So it's for this activity.
I think it's you use only constructor and you have the new.
And also I want to discuss this earlier.
That is real.
Hopefully they'll kind it out.
And here you can see there are three kinds Expedia, sequential and auto.
So it is exquisite.
You use it for the unions and sequential use for sectors.
So the sequential run over the sector will be exactly as it is.
Very opposite this structure in some other function.
So the members of this functions of the structure will be exactly in the order.
So the first one will be idea, and second and third one will be the secret key.
So there's this one get interchanged when you put this real control sequential.
Now it's different.
And I've got a union.
For this.
They are.
Priorities explicit.
You don't require any union keyword, the same struct you wrote to use it for, uh, union so that my
union.
And now we need to it to our.
The girl to where it was.
Public.
In.
Rule number.
And really we need to declare a field offset of the offset where this variable starts.
So if I said zero, then this would be the starting position sort of to declare another variable in.
Agreed.
And let me read to.
Veered off set of zero.
So the thing is, both start at the same location, same opposite.
So that means if you assign any value to this or in a model and if you build up this grade, then this
value will be printed because they share both the memory location and at the same offset.
So that create the.
So the name is my union.
Okay, so.
My union and musical store knew my union.
And so saying that raw numbers equals to that fight.
Now let's go and put this in the raw number.
We're just pretending it's where you know.
And here you can see the fight.
Now let's go and turn this to grade.
Now here you can see we got the same value because the the memory allocated is the same the four bytes.
That's also
the value of.
The size.
And we can see we got only four words for that to reduce.
No, let me go and change this field out to four.
So if you started the four so program that my union pressed for.
And if I go and assign a different number to the grade and also print the wrong number as well the number.
So we'll be seeing different values for these two variables.
Because of, uh, because of eight bytes, you can see the file, which is the value of row number and
the grade is under.
And the size of this union is gigabytes.
So this is about the basic societies and unions.
We're also seeing the national sectors now.
So we can also include this union in my centre.
So all I need to do is I can say public.
So that type of this variable I want to create, that is of the day my union.
My union that I'm on.
I am to.
Now, let me comment on this.
Now when I created this tea, I can simply access the members of this union by using be dot young to
dot this member.
B .2.0 number is equal to 69.
And let's go and put in this beta, a computer or a number.
Let's go and run this and you can see the values X and also let's print out the whole size.
So we are printing the size of this.
So down for whites.
For whites and this is for.
And this should be it, I guess.
So total will be 20.
So we got these 20 points and it's.
Jane this.
And now we get only 16.
So this is all about the cities and unions in this region.