(A)   Solution 1                                                Solution 2

struct student                      typedef struct

{                                   {

   char ssn[10];                       char ssn[10];

   char names[3][21];                  char names[3][21];

   float gpa;                          float gpa;

};                                  } STUDENT;


Solution 1 defines a structure called student, solution 2 defines a new data type called STUDENT, which is a structure.

Note that ssn needs to be 10 characters:  9 chars of the social security number plus one null termination character.  Likewise, each name is 20 characters plus the null termination character


(B)  Using structure of solution 1            Using structure of solution 2

struct student studentA;           STUDENT studentA;




strcpy (studentA.ssn, “123456789”);

strcpy (studentA.names[0], “Ima”);

strcpy (studentA.names[1], “College”);

strcpy (studentA.names[2], “Student”);

studentA.gpa = 3.85;


We need to call strcpy to add the strings, we cannot use the assignment (=) operator.

For gpa we can use the assignment operator.




pStudent = &studentA;




printf (“%s\n”, pStudent->names[2]);


printf (“%s\n”, (*pStudent).names[2]);


When accessing a structure with a pointer, we can use the arrow operator.  Alternatively, we can dereference the pointer to get the structure, and then use the member of (.) operator.  If using the second method, we need to make sure the dereferencing happens first, so we need to use the parentheses.