Concept
How do you access members of a statically declared structure?
ComputerScienceOne / Selection Operators
"Once we have a declared structure, we need to access its member variables and perhaps update them. If we have a statically declared structure, such as Student s; we can use the direct component selector operator ., which is simply just a period followed by the member variable we wish to access. Commonly, this is referred to simply as the dot operator.\n\nStudent s;\n\n//set values:\n\ns.id = 87654321;\n\ns.gpa = 3.9;\n\n//access values:\n\nprintf(\"Name: %s, %s\n\n\", s.lastName, s.firstName);\n\nprintf(\"GPA: %.2f\n\n\", s.gpa);\n\nWhen structures are nested, we can use the dot operator multiple times to access members variables of member variables.\n\ns.dateOfBirth.year = 2525;\n\ns.dateOfBirth.month = 12;\n\ns.dateOfBirth.date = 25;"
Related Ideas
- What topics are listed in this contents excerpt?ComputerScienceOne · Selection Operators . . . . . . . . . . . . . . . . . . . . . . . . . .
- How can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How can structures be dynamically allocated?ComputerScienceOne · Declaration & Initialization
- What is this concept?ComputerScienceOne · Comparison Operators
- What is covered in section 10.2?ComputerScienceOne · Using Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . .