Concept Flow - Accessing structure members
Define struct
Create struct variable
Access member using . or ->
Use member value
End
This flow shows how to define a struct, create a variable, access its members, and use those values.
struct Point {
int x;
int y;
};
struct Point p = {3, 4};
int sum = p.x + p.y;| Step | Action | Variable/Member Access | Value | Result/Output |
|---|---|---|---|---|
| 1 | Define struct Point | - | - | Struct type Point created with members x and y |
| 2 | Create variable p | p | x=3, y=4 | Variable p initialized with x=3 and y=4 |
| 3 | Access p.x | p.x | 3 | Value 3 retrieved |
| 4 | Access p.y | p.y | 4 | Value 4 retrieved |
| 5 | Calculate sum | p.x + p.y | 3 + 4 | sum = 7 |
| 6 | End | - | - | Program ends |
| Variable | Start | After Step 2 | After Step 5 |
|---|---|---|---|
| p.x | - | 3 | 3 |
| p.y | - | 4 | 4 |
| sum | - | - | 7 |
struct StructName { memberType memberName; };
struct StructName var = {values};
Access members with var.memberName (dot operator).
If pointer to struct, use pointer->memberName (arrow operator).
Use members to read or assign values.