Define a Supply Record
An array groups values of one element type. A workshop tool needs two different kinds of information: a name and a count. A struct groups these named members into one record.
struct Tool { ... }; defines the record type; it does not create a tool yet. Inside main, struct Tool tool creates one object. Its initializer assigns "Brush" to name and 3 to count, in declaration order. The dot in tool.count means “the count member of tool.”
const char *name stores a pointer to the string, not the characters inside the record. We can read that string through the pointer, but must not modify the string literal. The integer count occupies separate storage.
#include <stdio.h>
struct Tool {
const char *name;
int count;
};
int main(void) {
struct Tool tool = {"Brush", 3};
printf("%s: %d\n", tool.name, tool.count);
return 0;
}
Run the example and check for Brush: 3. Predict the output if the initializer used 4 instead: only the count would change. The next exercise gives you an editable record.