2.2 Named structs

Let us consider the following statement:

struct Student
{
  char name[NAMESIZE];
  char phone[PHNUMSIZE];
  char address[ADDRSIZE];
};

This is not a variable definition! There is no identifiers following the definition of the structure. Instead, we have an identifier between the keyword struct and the beginning of the structure definition. Student is the name of the structure itself. You can think of Student as the name of a cookie cutter.

A cookie cutter is not very useful, unless you plan to make cookies out of it.

Once we have a named struct definition, we can create variables from it:

struct Student studentA, studentB;

This is a variable definition that defines two variables, studentA and studentB. Both variables are of the type struct Student.



Copyright © 2006-08-30 by Tak Auyeung