In this lecture, you'll learn how you can define your very own data types in C. Those are called user-defined data types because you're the user and you're defining the data type. The way we do it, is we do it using the keyword struct, and to get at different members in our struct, we use something called the member selection operator which is really just the dot or period. So structs user-defined data types are really useful when we want to store pieces of related information together. That might sound fairly vague and abstract. So let's go look at an example of how we can define our own data type using a struct in a C program. Let's say we want a data type that will store three pieces of information about a student. We want to store the student ID, we want to store the student's current percentage in the class, and we want to store the student's current letter grade. The way we do this in C is we define our own user-defined data type. The way we'll do that, is we'll use the keyword or reserved word struct because it's a structure of data, and we'll give it a name, and then we will provide the fields or members for this structure. So our student number will be an integer. Our percentage will be a float, and our letter grade will be a char. No minuses and pluses for this particular professor just A, B, C, D, E, and F. So here's a struct that we've defined for a data type called student. You'll notice that the data types of the fields or members, the pieces of data in this struct are the data types we've already learned about. The student struct is comprised of or composed of those other data types. This is actually called a composite data type. Now, you might think that at this point, we can just declare a variable of type student and give it a variable name because that's how we've done it so far. We've put a data type followed by a variable name. But if I compile, I get this error that says, "Student is an undeclared identifier." I can work around this just to make it convenient to use student as a data type by adding the following line. I'll do typedef, so define a type and it is a struct, and it's named Student and I just say and here's how I want to use that actual data type in the rest of my code. As you can see, if I build now, my build succeeds. So let's actually look at initializing and printing out the information for this student. So I'll add a comment. One way we can initialize is to actually do the following. We can say, equal and then we put curly braces, and then we provide a value for each of the field or members. So for the student number, I'll use 101010101. For their percentage, it will be 89.5 and for their grade because their professor doesn't believe in rounding, we'll give them a B. So this will actually fill up each of those fields of the student0 variable with these values that we've provided. Let's actually print those out. So we know to use printf. I'll actually provide a heading for this particular student. I know I'll want a new line at the end of it, and I'll add a nice little line as well. Nothing new yet here. Here comes the new stuff. So we will print the information about the student. So the first thing we'll print is their number. We know their number is an integer. So the format specifier we want is percent d. Now, we want to access that number field. The way we do it, is with the variable name dot field name. So if I control F5 at this point, you can see that we've printed out their numbers successfully. I'll go ahead and add that line that I always like between the results of our program and the standard message we get. I'll just add the other items as well. So we'll test them one at a time to make sure they're working properly. We know the format specifier for floating point number is percent f, and I'll run it. Obviously, I need another new line but it's 89.5. So let's do two things. Let's add that new line, and I know I'm going to need it here as well. Let's print out the percent to one decimal place. As you can see, we've printed that correctly as well. Now, we want to print out their letter grade. So we'll printf. We'll label our output. Now, we don't really know the format specifier yet for a character. So we might start guessing. We might say, "Percent d should work fine." It certainly doesn't crash. It says our grade is 66, which happens to be the decimal value for capital B in the ASCII table, but that's not really what we want. So we guess percent f, and try again and that's not right. We get a zero, and then we just go look it up in the documentation and discover that it's percent C for a character, for our format specifier. So I run that code and we get the B. Now, you may not want to initialize this way. So let me show you how to initialize another way. I'm going to copy and paste, and of course, anytime you copy and paste, you have to be careful to change the things that you want to change. I'm going to get rid of this initialization. I know because I'm printing out the data for two students, I'm going to want to separate that information with a blank line. So right up here, I can just print another new line. At this point, we haven't actually assigned values to each of the fields for student1. So if you want to just do a direct assignment, we can say, "Student1.number is equal to some integer literal." So we're accessing the field of the struct the same way we access the field here. This time we're reading it, so we can output it. This time we're assigning to it, so we're giving it a value. So let's do the other two as well. Percent is let's say a 59.99, and we know about this professor. So this is an F. Let's go ahead and run this code, and there you go. Both students have been initialized properly, and we're able to access the fields of those student variables to output their values. What we learned in this lecture is, how to define a struct. How to make it convenient to declare variables of that struct. How to declare that variable and initialize using curly braces. We saw how to access fields, which are also called members of the struct for output here. We also saw how to access those fields so that we can assign values to them. To recap. In this lecture, we learned how to define our own data type, and how to use that data type when we declare a variable of that data type.