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?
✗ Incorrect
The dot operator (.) is used to access members of a structure variable directly.
How do you access a structure member through a pointer in C?
✗ Incorrect
The arrow operator (->) is used to access members through a pointer to a structure.
Given
struct Person { int age; } *ptr;, how do you access the age member?✗ Incorrect
You use
ptr->age to access the age member through the pointer.What will happen if you try to use the dot operator on a pointer to a structure?
✗ Incorrect
Using the dot operator on a pointer to a structure causes a compilation error because the pointer must be dereferenced first or use the arrow operator.
If
p is a structure variable, which of these is correct to assign 5 to member val?✗ Incorrect
You use the dot operator to assign a value to a member of a structure variable.
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.