Recall & Review
beginner
What is a nested structure in C++?
A nested structure is a structure defined inside another structure. It helps organize related data by grouping structures within structures.
Click to reveal answer
beginner
How do you access a member of a nested structure?
You use the dot operator (.) for each level. For example, if
outer has a nested structure inner, access a member m as outer.inner.m.Click to reveal answer
intermediate
Can nested structures have their own functions in C++?
Yes, nested structures in C++ can have their own member functions. They are typically just data containers. You can define functions inside the outer structure that work with nested structures.
Click to reveal answer
intermediate
Why use nested structures instead of separate structures?
Nested structures group related data tightly, making code clearer and easier to manage. It shows a clear relationship between data parts, like an address inside a person.
Click to reveal answer
beginner
Write a simple example of a nested structure in C++.
Example:<br>
struct Person {
std::string name;
struct Address {
std::string city;
int zip;
} address; // nested structure
};Click to reveal answer
How do you declare a nested structure in C++?
✗ Incorrect
Nested structures are declared by defining one struct inside another struct.
How to access member 'zip' inside nested structure 'address' of 'person'?
✗ Incorrect
Use dot operator for each level: person.address.zip
Can nested structures contain member functions in C++?
✗ Incorrect
Structures can have member functions, but nested structures usually hold data only.
What is a benefit of using nested structures?
✗ Incorrect
Nested structures help organize related data clearly.
Which operator is used to access members of nested structures?
✗ Incorrect
The dot operator (.) is used to access members of nested structures.
Explain what nested structures are and how to access their members in C++.
Think about a structure inside another structure and how you reach the inner data.
You got /3 concepts.
Describe why nested structures are useful and give a simple example.
Consider how you might store an address inside a person.
You got /3 concepts.