Declare and initialize variables
Give the shelf counts names
A box of glue tubes has arrived at the repair workshop. Keep the tube count and shelf count in separate variables so one can change without changing the other.
#include <stdio.h>
int main(void) {
int tubes = 3;
int shelves = 2;
printf("Glue tubes: %d; shelves: %d\n", tubes, shelves);
return 0;
}
int tubes = 3; has three parts: a type (int), a name (tubes), and an initial value (3). The second declaration creates separate storage for shelves; it does not replace tubes.
Names can contain letters, digits, and underscores, but cannot start with a digit. Use names such as tube_count, not 3tubes; uppercase and lowercase letters are different. Avoid C keywords such as int, which already have a language meaning.
Run the example and match each %d to its argument. The first reads tubes, and the second reads shelves. If the initial tube count were 4, only the first number would change.
A declaration without an initializer, such as int tubes;, would not give this local variable a reliable starting count. Give your counts values before printing them. Next, you'll label a different bin.