struct student {
char name[30];
char address[60];
int extension;
int grad_year;
float gpa;
};
struct tag {
member declarations
};
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;
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);
print_student(new_student);
new_student
will be
copied into the corresponding members of
this_student
.