Are you equally confused about arrays?
Let's say you wanted to store the dimensions of a box using an array.
Code:
int mybox[3];
Which looks like this laid out in memory.
+----------+
| mybox[0] |
+----------+
| mybox[1] |
+----------+
| mybox[2] |
+----------+
Now set some sizes for our box.
Code:
// To keep our sanity, we assign specific indices of the array to be for a
// particular purpose, so we give each one a name.
#define LENGTH_INDEX 0
#define WIDTH_INDEX 1
#define HEIGHT_INDEX 2
mybox[LENGTH_INDEX] = 22;
mybox[WIDTH_INDEX] = 33;
mybox[HEIGHT_INDEX] = 44;
Now do the same thing with a struct.
Code:
struct box {
int length;
int width;
int height;
};
struct box mybox;
Which looks like this laid out in memory.
+--------+
| length |
+--------+
| width |
+--------+
| height |
+--------+
See the similarity?
Now set some sizes for our box.
Code:
mybox.length = 22;
mybox.width = 33;
mybox.height = 44;
So the thing we call a length, in the thing we call a box has been written as either
mybox[LENGTH_INDEX] = 22;
or
mybox.length = 22;