Structure Declaration

This example declares a structure. The new type is named Employee:
struct Employee        // Employee is a new type
{
  char firstName[10];  // first name is a char array
  char lastName[12];   // last name is char array
  char middleInitial;  // middle initial is char
  float salary;        // yearly pay is float
  int age;             // age is int
  int years;           // years of service is int
};
Now, we can use it to declare a variable of this new type:
Employee clerk;        // clerk is an Employee
This is what the structure looks like in memory.
     clerk.firstName ®  ?  ?  ?  ?  ?  ?  ?  ?  ?  ?
      clerk.lastName ®  ?  ?  ?  ?  ?  ?  ?  ?  ?  ?  ?  ?
 clerk.middleInitial ®  ?
        clerk.salary ®  ?  ?  ?  ?
           clerk.age ®  ?  ?
         clerk.years ®  ?  ?
Previous page
Next page

Back to Lesson 14 Index
Back to Outline