|
|
|
|
|
|
|
If we declare a variable of type StudentRec |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
|
|
|
Therefore, the expression |
|
|
|
|
|
|
|
|
denotes a struct; the expression |
|
|
|
|
|
|
|
|
denotes an array; and the expression |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|