Hello everyone, my name is Aditya and we are continuing with this C programming course.
In part one we had discussed how a structure is made and after that we had seen how it is defined and how we can access the members in it.
So, we have seen this theoretically and, in this video, which means, in the part two video, we are going to discuss it practically within the text editor.
Which means we will straight away go to our Visual Studio code and there we will see how we make one structure, how we use and how we make a variable of its name and store the values in it.
So, without any delay we will start and straight away go to Visual Studio code.
Here you can see that we have made a structure’s program and here the first two lines which are there, those are the preprocessor commands, in which we are including one file stdio.h and the second file string.h.
Why? Because we are going to use strings as well here.
So, with the help of both these preprocessor commands, we have imported these two files, we have included them.
So, now, if we go ahead, we are not able to see the main function first, before the main function here we can see that there is a structure made which starts with struct keyword.
So, we had discussed in the last video how the compiler knows that this is a structure, so he knows with the struct keyword that here there is one structure made.
What is this structure? This is one group of different types of data type variables.
So, we saw here that there is a struct keyword and employee is written.
So, with this we understand that our structure’s name is employee.
And the values that are going to be inside, the first would be of integer type and second would be of character type.
So, here we are going to store employee’s information.
In the same way we had discussed in the previous example but here we will include only two things of the employees, we will be considering only two pieces of information.
First information is of ID, it means that we will be storing employee ID.
So, that's why we made the first variable of employee ID.
Now, the second item or the second member of this structure is our name.
Now, you can see the name should be an array, but since it is character type, with this we will get to know that this would be one string.
The name will become one string whose size is 50.
So, in this basically we will get stored the employee's name So, this is about making a structure or to make the data type.
So, how will this data type be used, this data type will be used for one variable.
So, how will we define that variable, how will we declare it, that we will see in this particular video So, here you can see that after writing the structure, after defining it, after closing the curly brackets, over here you can see something E1 written and this E1 is basically our variable.
How is it the variable? We are making one ID variable, its data type is integer, so integer we write first and after that we write the ID.
Since, our entire structure is the type of data type so, here in front before the semicolon we can write the variable’s name and what that variable will be, it will be of structure type meaning an employee data type variable.
So, in this way our work will go on.
So, whenever we want ID or name for one employee.
So, that one employee would be represented by e1.
Going inside the e1 or through the e1, we will store its ID and its name, with the help of the structure.
So, in this way, if we want to add two people or three people, three employees we have to add.
We will use e2 here.
Similarly, we will use e3 or if we want to use some other name, we will put qw4.
So, in this way we can make different variables, through which we have to access here.
So, this was about making the variables through which we will access our structure.
This is not the only way where we can make this kind of variable with struct type of data type.
There is a way other than this as well.
We will see even that quickly.
Like we make a normal variable.
I will remove this E1.
So, when we make a normal variable, what do we write first? We write our data type, so what is the data type here? Our data type is struct employee.
So, we have written the data type’s name before our variable’s name.
And after that we made the variable, e1 and we wrote a semicolon.
So, here you can see that struct employee’s data type variable we had made which is e1.
And from inside e1 we will access our id and name.
So, in this way the flow goes on, our structure’s work goes on.
So, we have made one structure which means we have made the data type.
And on the basis of that data type, we can make infinite variables.
For this example, we have made only one variable e1.
So, e1 is for the 1st employee.
So, we have made only one.
Now in this way we will store with the help of name and ID, we will see that.
So, we are going to store the employee’s information.
So, first of all, I have to store my ID.
So, what will I do? I will take my variable here and I will write e1 and here I have seen that the member access operator which is dot, we will be using it here.
And after that, we will be writing about a member's name, like if I have to insert the ID I will mention e1.id And whatever value I have to insert in it, it will get inserted in it.
In the same way if I want to insert the name, I will make use of the string copy function as we are talking about strings and what will be called by e1.name? This particular member will be called which is a string and with the help of string copy in the right, this learnvern which is written we will copy that in e1.name.
So, whenever we refer to e1 by the name, we will get our learnvern.
So, in this way, we will be able to store our ID and name for each variable.
So, in this case, there was only one variable e1.
So, we have defined our values as e1.name and e1.id and inserted them.
So, this was the declaration and initialization of our structure.
After that, we will see how we will print our data from our structure.
So, with the help of a structure the variable that we have already made e1.
So, we will write e1.id.
So, we will get e1.id which means we will get that particular employee’s id or the even employee’s id.
And we will get it printed with our printf statement.
In the same way if we write e1.name.
So, we will get e1 employee’s name printed, with the help of printf statement.
So, this was a very easy flow, in which we made one data type, that means one structure, which was called as employee and in that we have defined different types of variables and how will we access those variables, we will be making variable of this particular structure’s data type and with that variable we will access each member in our structure.
So, in this way our structure’s flow goes on.
And in this way, we use the user defined data types.
If in the employees we want to store more information, we can increase the members.
Apart from ID, name, we can keep mobile number’s option, we can keep email’s option.
So, in this way whatever is our requirement, according to that we will make the things.
So that's why we call it a user defined data type.
So, we have seen the meaning of each and every line here.
Now, we will save it and run it and see what our output is.
So, you can see that, here for now we had made only one employee.
As soon as we wanted to print a statement here, which was employee 1 ID is, in front of employee 1 Id we printed 101, which was the employee 1’s ID, how was it accessed, with e1.id.
Similarly, if we want to print employee 1’s name, we wrote e1.name and that got printed here, Leanrvern.
So, this is the flow of our structures, and in this way, we can use it as per ourselves, we can customise it and we can effectively use it in our program.
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.
Very happy 😄😁
Very happy and greatful, thank you , great course.
Super for poor students to learn software course languages TQ