0
0
Cprogramming~5 mins

Accessing structure members - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a structure in C?
A structure in C is a user-defined data type that groups different variables under one name, allowing you to store related data together.
Click to reveal answer
beginner
How do you access a member of a structure variable in C?
You use the dot operator (.) to access a member of a structure variable. For example, if person is a structure variable and age is a member, you write person.age.
Click to reveal answer
beginner
How do you access a member of a structure through a pointer in C?
You use the arrow operator (->) to access a member of a structure through a pointer. For example, if p is a pointer to a structure and name is a member, you write p->name.
Click to reveal answer
intermediate
What is the difference between the dot (.) and arrow (->) operators in C structures?
The dot operator (.) is used to access members of a structure variable directly, while the arrow operator (->) is used to access members through a pointer to a structure.
Click to reveal answer
beginner
Given struct Point { int x; int y; } p;, how do you set the x coordinate to 10?
You write p.x = 10; to set the x coordinate of the structure variable p to 10.
Click to reveal answer
Which operator is used to access a member of a structure variable in C?
A. (dot)
B-> (arrow)
C* (asterisk)
D& (ampersand)
How do you access a structure member through a pointer in C?
AUsing the asterisk (*)
BUsing the dot operator (.)
CUsing the arrow operator (->)
DUsing the ampersand (&)
Given struct Person { int age; } *ptr;, how do you access the age member?
Aptr.age
B&ptr.age
C*ptr.age
Dptr->age
What will happen if you try to use the dot operator on a pointer to a structure?
AIt works fine
BIt causes a compilation error
CIt accesses the member correctly
DIt dereferences the pointer automatically
If p is a structure variable, which of these is correct to assign 5 to member val?
Ap.val = 5;
B*p.val = 5;
Cp->val = 5;
D&p.val = 5;
Explain how to access members of a structure variable and a pointer to a structure in C.
Think about how you access properties of an object directly versus through a pointer.
You got /3 concepts.
    Describe the difference between the dot (.) and arrow (->) operators when working with structures in C.
    Consider what happens when you have a pointer versus a normal variable.
    You got /3 concepts.