|
Example of a struct definition: (for simplicity: without gaps)
struct myStruct { int x; int y; int z; } |
Storage format of every struct myStruct variable:
Example of a struct definition: (for simplicity: without gaps)
struct myStruct { int x; int y; int z; } |
Information extracted and stored by the C compiler:
|
C's syntax to access (= use) the components inside a struct:
struct myStrunct a, b; // Defines 2 struct varriables a.x = the x component inside struct variable a a.y = the y component inside struct variable a a.z = the z component inside struct variable a b.x = the x component inside struct variable b b.y = the y component inside struct variable b b.z = the z component inside struct variable b |
Important fact:
|
C's syntax to access (= use) the components inside a struct:
struct myStrunct a, b; // Defines 2 struct varriables a.x = the x component inside struct variable a a.y = the y component inside struct variable a a.z = the z component inside struct variable a b.x = the x component inside struct variable b b.y = the y component inside struct variable b b.z = the z component inside struct variable b |
Accessing the components inside a struct myStruct variable:
Access a.x: base address of a + offset 0 Access a.y: base address of a + offset 4 Access a.z: base address of a + offset 8 Access b.x: base address of b + offset 0 Access b.y: base address of b + offset 4 Access b.z: base address of b + offset 8 |