Hello everyone, my name is Aditya and we are continuing this C Programming course.
In the last video we discussed strings.
We saw that what is the need of these strings, how it can be defined and declared and how do we store the elements in them? All these things we had learned in the last video about strings.
In this video we will be discussing our fourth derived data type which is called structures.
So, we are talking about structures used in C programming.
So, what are these structures? Why are they used? And how is the structure of these structures done? Is it different from the arrays or is it the same? Is it similar to strings or different? All the answers to these questions we will be searching for in this particular presentation or in this particular video.
So, we will quickly go on to the next slide and find answers to all these questions.
So, the first question which is there is what are structures? So, if we talk about the definition, if we go as per the definition, the definition says that it is a collection of logically related data items of different data types grouped under a single name.
So, this is a normal definition but if we want to understand it in layman's terms.
So, what does it basically mean? This says that a structure is the type of a group and which group is it? logically related data items.
So, what are the data items over here? So, data items are basically the variables.
So, the different types of variables that are there with us, some variables would be of an integer type, some would be of character type or float type.
So, the different data types of the variables that are there or if we see them logically, if there is any connection that is made between them.
We will collect all those variables and put it in a group which we call a structure.
This is something to concentrate on.
This group is called as structures.
And with the help of this structure, we make a new data type.
So, whenever we have this kind of a requirement in which we have to store the value in integer type variable, in a float type variable also or in the character type of variable also.
So, the one which will fulfil all these things, that type of a data type would be the structure.
And structures are basically user defined which means the programmer or the user who is writing the program, he will define how the structure will be, how many variables would be in that, what would be the type of variables, what would be its limit? So, all these things are defined by our user.
That's why it is called a user defined data type.
So, we will take one example with that we will understand this clearly.
Suppose we have a company and what we have to do is the details and information of all our employees, we have to store them in our program.
Now we have 50 employees.
Let's say we have 100 employees.
So, related to each employee, we will require each employee’s ID, his full name or email address, mobile number, address, All these things we will require from each employee and we will have to store them in the program.
So, will we make different variables for all this information, will it be feasible? If there are 1000 or 5000 employees instead of 50.
Will I make each variable for 5000 employees? Will I be able to remember the names, even if I make an array, in an array each unit would be interlinked but how will be the employee’s data? It will be of different data types.
In arrays what happens we can store similar data type’s data but about the employee we need the employee ID, along with that we will also require the name as well, which will not come in the integer, it will come in the character, which means in string type.
So, the different types of variables that we will be using here.
So, to store all these we will have to make a structure, so what will be the structure, it will be a group of different types of variables.
When we have to store the data of any employee.
So, what we will do is, we will straight away use the structure.
And the variables of structure which are there, in that one by one we will store the values.
And when we give the numbering to the employee, like employee 1 and employee 2 and in this way, employee 50.
If we wanted details about employee 1, along with employee 1, whatever variables are attached to it, which means all the variables in that group, we can straight away take those and access it and we can get to know that information about it.
So, this is the functionality about our structures, that's why they are different from arrays and strings or any other derived data type.
So, we have talked about our structures.
Now we will talk about how we will define the structure, how we will tell them that our compiler understands, that we have made a structure.
So, the structure definition template is terminated with a semicolon.
So, like we were making derived data types like strings.
In front of the curly brackets, we used to not put the semicolon but here in the structure after the curly bracket we will be putting one semicolon, which has a special meaning, which we will discuss in the coming slides.
For now, we will see that our structure will be getting enclosed with our curly brackets.
For this we will quickly see our syntax If we talk about the syntax.
So here a struct named keyword is being used, which will tell our compiler that we are defining a structure.
So here the struct keyword is used, in front of it we will write our structure’s name, through which our structure will be identified.
So now we have written the name of the structure.
Now our curly brackets will start.
So, let's suppose we have to store information of the employees in the curly brackets.
So, we will require different types of variables.
So, in this way, we will write the data type of the first variable and then after writing member 1 and store it.
So, in this way, we will write different variables and we can take integer, float or character, we will store it in different types of variables.
So, this would be our structures definition’s actual structure.
So, this was about the definition, if we move ahead, you will see that we have stored the value in our variables in some or the other way.
But if we want to access it, how will that be done? So, the individual members of structure can be accessed using the member access operator, which is defined with a full stop, one dot.
Now what is this saying? If we want to access individual members, how can we do that? We will access them with a member access operator, which is defined by a full stop, with a small dot.
How is that defined? Come let's see.
This dot basically connects a structure variable and the structure member.
So,we will see how it is getting connected.
So, first of all our structure variable’s name will come after that we will put this dot means a full stop and then we will write the name of a structure's member.
So as and when we have to store in different members, we will keep changing the structure member’s name and our structure variable will remain the same.
So, in this way.
We will quickly access every value and every member for one particular structure variable.
For now, you might find these things complex, you might not be able to understand them because till now we were talking theoretically about this particular topic or about this structure.
So now, we will talk practically, we will make the structure and see how they are used.
How we can make different types of members in them.
All these things we will be seeing but in the next video.
But for this video, this is it, in which we saw how a structure is made, how its value is accessed? Now in the next video, part two of this video, we will see and discover practically by making our structure, we will go in our text editor and we will make our structure for one particular scenario.
And as per that structure we will make different variables and members and we will use it because of which we will understand the structures properly.
So, till that time, goodbye and we will continue with this structure topic in the next video.
Thank you so much.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
Share a personalized message with your friends.