< previous page page_822 next page >

Page 822
If we declare a variable of type StudentRec
StudentRec student;
then what is the syntax for selecting the first letter of a student's last name (that is, for selecting element 0 of the lastName member of student)? The dot operator is a binary (two-operand) operator; its left operand denotes a struct variable, and its right operand is a member name:
StructVariable.MemberName
The [] operator is a unary (one-operand) operator; it comes immediately after an expression denoting an array:
Array[IndexExpression]
Therefore, the expression
student
denotes a struct; the expression
student.lastName
denotes an array; and the expression
student.lastName[0]
denotes a stringthe string that is located in element 0 of the student.lastName array.
With arrays of structs, again you have to be sure that the [] and . operators are in the proper positions. Given the declaration
StudentRec gradeBook[150];
we can access the gpa member of the first element of the gradeBook array with the expression
gradeBook[0].gpa

 
< previous page page_822 next page >