0
0
Cprogramming~5 mins

Nested structures - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a nested structure in C?
A nested structure is a structure that contains another structure as one of its members. It helps organize related data in a clear way.
Click to reveal answer
beginner
How do you access a member of a nested structure in C?
You use the dot operator (.) for normal structures and the arrow operator (->) for pointers. For nested structures, you chain these operators, like outer.inner.member.
Click to reveal answer
intermediate
Why use nested structures instead of separate structures?
Nested structures group related data together inside a bigger structure. This makes the code easier to read and maintain, like putting related tools in one toolbox.
Click to reveal answer
beginner
Example: Define a structure Address with city and zip, then a structure Person with name and Address nested inside.
struct Address { char city[50]; int zip; }; struct Person { char name[50]; struct Address address; };
Click to reveal answer
intermediate
How do you initialize a nested structure in C?
You can initialize nested structures by listing values in order, like struct Person p = {"Alice", {"New York", 10001}};.
Click to reveal answer
Which operator is used to access a member of a nested structure variable in C?
ADot operator (.)
BArrow operator (->)
CBoth A and C depending on context
DComma operator (,)
What is the correct way to define a nested structure in C?
Astruct Outer { int x; struct Inner y; };
Bstruct Outer { int x; Inner y; };
Cstruct Outer { int x; struct Inner; y; };
Dstruct Outer { int x; struct Inner(); y; };
Given struct Person { char name[20]; struct Address addr; };, how do you access the city of a Person variable p?
Ap.addr.city
Bp->addr->city
Cp.city.addr
Dp.addr->city
Why might you use nested structures in a program?
ATo make the program run faster
BTo group related data inside a bigger structure
CTo avoid using pointers
DTo reduce memory usage always
How do you initialize a nested structure in C?
Astruct Person p = {"Bob" + {"LA", 90001}};
Bstruct Person p = {"Bob", "LA", 90001};
Cstruct Person p = {"Bob"; {"LA", 90001}};
Dstruct Person p = {"Bob", {"LA", 90001}};
Explain what nested structures are and how you access their members in C.
Think about how you open a box inside another box to get an item.
You got /3 concepts.
    Describe how to define and initialize a nested structure with an example.
    Imagine filling out a form with sections inside sections.
    You got /3 concepts.