Hello and welcome back to this practical module of C programming course. ….. Here like before we will be discussing a new practical, where we will be discussing structures concept. Early we must have seen structures, where the structures are made, it is written on the main function and we make variables of structure types and through that variable, we take inputs of structure’s formation So, all these things related to structure we have seen before. In this program we are going to see one “use case” example, which means in real life when we have to store a certain data, how it will be stored with the help of structures, that is what we are going to see here. So, without any delay we will start and we will see the name of today's problem. So, the name of the problem is structure of student data. And what we have to do is, we have to store some information of the student and how is this information, here would be student’s roll number, student’s name and along with that there would be student’s marks. So, here we have to store these informations related to students. So, here for every student what we will do is make a variable of structure and through it basically, through the structure we will be storing the student’s details. So, how does this work? We will see and move towards our text editor. So, now we have come here in our Visual Studio code. And you can see that there is a template ready, where we have written the preprocessor command and we have written one body of the main function. So, what is the first thing to make a structure? We have to use struct keyword and along with that we have to write the name of the structure, the structure which we are going to make and along with that we have to write some members in it, which would be the part of that structure, whenever we'll be making the structure type variable, input of all those things they would be taking through it. That’s why we are going to make a structure over here to store the information of the students. So, here what we have done is we have made one structure named student and inside that we have written 3 different members. So, the first member, would be our name, which is the first name. What is this? This is going to be a string definitely because we have kept a data type character here and we have also given the size of 50. So, we have to give the first name of the student in this particular string. Along with that you can see that our second member is roll. So, here we will be storing the roll number of the student and the third member is of marks. So, here he will be storing one marks, related to any student. So, this is our entire structure. Now you will see that our in front of the curly brackets we have not put directly the semicolon, when we had learned the structure. We had also seen that the variable of the structure we can make it into two ways, immediately after the curly brackets ends and the semicolon, we can write in between them or we can make them directly in the main function by using our structures name. Here what we have done is after the curly brackets we have taken one array of students and now what we will do is through for loop we will be storing structure student type data in each element of array. So, what we used to do first in the arrays, we used to store one value inside the array. But with the help this concepts, what we are doing is we are making the structure in every element and in the structure we are storing different member’s value. So, that's why we have taken s5 array. This means that we will be storing five student’s information over here. So, now we will move ahead and the first thing that we will see is we have made one i named variable inside our main function, which would definitely be used for the for loop. And now we have made the structure over here and along with that we have also defined the variables, which all structures variables are going to be there. Now the time comes to take the input. So, to take the input we have made one for loop over here, you can see that first of all we are telling our user that enter the information of students. So, the information related to the students that we have to input over here and how is it getting input over here? We will be seeing it here. We have made one for loop and you can see that I’s value we have started from zero and till where it is going on? It will go on till it is less than five. It means that, for loop will work five times. Which means it would be running for five times. So, I’s value will be zero at first then one and two, three and then four. In this way it will not go up till five, it will stop at 4. So, this was about the for loop, how many times it will run. Now we will come into for loop, you can see that we have written few statements in for loop which are going to be executed definitely. So, you can see that whenever for loop is running for the first time. So, what have we done? What we have done is inside the roll number of our first student, we have stored i+1 value. Since we were starting the I’s value from zero. So, you can see that 0+1, which means inside the roll number of the earlier student, we are storing one value by default. What will happen because of this, we'll be able to create one alignment for all the five students. First of all, we will take the student one’s data and that's why we have taken his roll number as one. When we will take for the second student, which means the data of student two and at that time we have to make its roll number as 2. In the same way, 3 will be the roll number of 3rd student, 4 will be for the 4th student and 5 would be our 5th student’s roll number. So here we are going to store the information of five students. All the student’s roll number we will declare by default. The first student’s roll number would be one and it will go on further. Now you will see that we are using one printf statement and writing for roll number, whatever number will be there on that particular time, on that situation, that should be printed over here. So, for the first student when printf statement will be printed for roll number one and after that what we have to do is we have to enter first name of that particular student and we have to store his marks respectively. So, you can see that time to time we will get this statement on the output screen. First our program will say that roll number one, you have to enter these details. And the first detail which we have to enter is the first name. So, you can see that how we have taken the first name’s input. Like we took the first name’s input, for the same index position element, what we will do is we will also take the input of the marks. So, in this way, what do you have to do is you have to take the data input by using dot operator. Since there are five students here, we have used for loop, this s array will go on five times and I’s value will go till 1, 2, 3 till four starting from 0. So, this was about how we have to take the data and store it with the help of our structure. Now is the time to print the data of the student. So, for that what we will do is, for that we will put a logic of display information and again this will be for loop because again we have five students and their information we have stored in one array. So that's why we put for loop over here, its number of repetition will be same like the first for loop, which means even this will run for five times because we have only five students. So, what is the first printf statement printing? That will print the roll no of our students and here I have made plus one because we are starting the I’s value from zero, so the first student’s roll number is 1. So, we will do “i+1” whenever the I’s value will be one it will be displaying second student’s information, that's why its roll number will also be two at that moment. In the same way when we are going to print the first name of any respective students, at that time we are making use of puts and whichever was the first name of that particular element that we will be print for our students along with that It's corresponding marks for i’s value, even that we will print with the help of printf statement and we have even put the format specifier over here for the same thing. So, this entire flow that how we can represent the student’s data with the help of structure and can give the output, now we have made this entire program. Now comes the turn, how this can be seen whether it is working properly or not. So, for that, what we will do is we will run it and see whether our program is running successfully. So, now it is asking us for roll number 1. Which means the 1st student’s information we have to store here. Now what we'll do here is we will create the 1st student with a dummy name, learnvern. After that lets suppose we will keep the marks as 78. We are going to keep the marks below 100. Our second student, we will make him Ram and his marks would be 82. Along with that. We will write the name Rakesh of the third student, for him we will put 36 marks. We will put the information of the 4th student and we will keep the name as Joe and for that we will give him 79 marks. The third student’s name we will keep as Neel and you can see that his marks we have given as 16. So these are very less marks. But these are dummy data, so no need to worry. So, we have written the five student’s marks over here. As soon as we enter here. You can see that we have got few more statements printed over here. So, we will scroll up a little. So, you can see that as soon as we have input all the data for everyone. Our display function also started working and all the printf statements of displaying got executed. So, roll number one’s name and his marks respectively we have printed them here. Along with that, whose roll number was 2, 3, 4 and 5, all this information we have printed over here, you can see that for Neel we have given 16 marks and his roll number was obviously five. So, we have got all the information printed over here. So, in this way, if you want to do any other type of real life representation, apart from students, you can do it over here. So, we have seen how the structure is used in a real life scenario in our program to create it. So, you can practice this program.
If you think that there is any part of this video or this topic, you might have not understood then you can ask us any query or question related to that topic without any inhibition.