The Structure of C

C, like many other languages, provides the ability to construct records. In C, they are called structures . If we would like to create the structure for the student described by: we would write in C:
struct student {
   char name[30];
   char address[60];
   int extension;
   int grad_year;
   float gpa;
};

The general form of such declarations is
struct tag {
   member declarations
};

where the tag is a name that we will use to refer to this new composite type of data and the member declarations may be any standard C variable declaration.

One thing may not be clear from this. Such a declaration doesn't really create any of these students. In other words, it's not creating variables or arrays, it's just saying what such a student will look like when we get around to creating any. To actually create a variable to hold a student we would use the syntax:


struct student new_student;

Here we are creating (defining) a variable called new_student that will hold data of the type we described earlier. (We'll see later that we can even create arrays of structures and pointers to structures .)

Just as most any variable declaration can also be used to declare a parameter (you'll remember that arrays are a bit different), we can use structure definitions for parameters as well. So we might have function with the prototype:


void print_student(struct student this_student);

and we could call it with a statement like:
print_student(new_student);

and it will operate as you would likely expect. Namely, each of the members of new_student will be copied into the corresponding members of this_student .
Write a single variable declaration for two variables called x and y both of which are structures whose tag is called thingy .