Hello everyone, in this video, we are going to be talking about structures. So what is a structure? A structure structure is just an abstract data type, which groups together logically related data. So let's see that with an example. So we declare a struct by the syntax type, the name of the structure, and struct. We have created a new structure here.
So the way to initialize a variable with this structure, we can we can do either of the two things, you can do c is equal to car or you can do c one, c one. So you might have noticed that whenever we were declaring a variable, the syntax was variable, where the name of the variable and the data type. So what we can infer from this structure is essentially a data type, which groups together logically related data This is called Data encapsulation. Now we're going to be defining some member data types, member data variables inside of the car. So a car might have a name, which can be a string, it might have an H, which can be an integer. And also, it can also have a model number, which can also be an integer.
So, to define a car, we can initialize an empty structure, simply do this, and it's gonna initialize all of the all of the member data types as zero as a null type. So you can see a string is defined as this integers are defined as zero. So to initialize a structure as an object, you can simply follow this syntax to one good intro to that So, the name of the structure followed by curly braces and all the data types you can define in this way. One more technique is this, the Object Notation. So you can do a Chevy, you can do an age on it. And you can do more than number on it.
And just make sure that when you're writing like this, you always you always suffix the last data type the column Gouda and this. So, it is actually very desirable that you write it in this way, because in the case of very large structures, you won't be able to tell which data structure is which data type is which. So and one more thing is that you can also define methods on top of your structures. So the way to do that is you write a function, and instead of writing the function name, you write the name of the structure with an object And then you simply do simply write your function as you want to write and this function can print a guy right and then to call this function, you simply do a C dot print notice that these function this method is attached to the object of this structure.
So, this is a really nice way of logically relating all of the data which is related to one another. So a car has an age number and all a car also has a brand. A car can also have a function which can say okay, you have to drive. So I can also have a drive function driving a vehicle seat sudo sudo sudo tray Try not to return something from the function simply do a fun name of the structure and then get name. And what gate name does is it returns a string which you're going to see is going to be the name of the car. Now let's see what happens.
See your name? Yeah, you got the name of the car. So all of this data is related logically. And this is what is a structure. So see you in the next video, we are going to be talking about interfaces. Thank you.