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
- How do you create and use an array of structures in C?ComputerScienceOne · Arrays of Structures
- How do you pass an array of pointers to structures to a function?ComputerScienceOne · Passing Arrays of Structures
- How are structure instances declared and initialized?ComputerScienceOne · Declaration & Initialization
- How can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How can an array of structure pointers make swapping structures more efficient?ComputerScienceOne · Arrays of Structures
- How are structures defined and named in C?ComputerScienceOne · Alternative Declarations
- How can a date be modeled using a nested structure?ComputerScienceOne · Nested Structures
- How can structures be dynamically allocated?ComputerScienceOne · Declaration & Initialization