Using #define in this way, CELSIUS is a symbolic constant. Everywhere that CELSIUS appears in this source file it is replaced with 20, simple text substitution.
So the following line:
for (CELSIUS = LOWER; CELSIUS <= UPPER; CELSIUS = CELSIUS + STEP)
becomes
for (20 = LOWER; 20 <= UPPER; 20 = 20 + STEP)
As you can see, this doesn't make sense in this context as 20 will be interpreted during compilation (after the text substitution has taken place) as an integer literal, not as a variable. You can't assign a value to an integer literal.
A better example might be to declare a variable named Celsius as an int value, then use symbolic constants for the (unchanging) values of UPPER, LOWER and STEP. For example:
#define LOWER 0
#define UPPER 100
#define STEP 2
int Celsius;
for(Celsius = LOWER; Celsius <= UPPER; Celsius += STEP)
......
......
This would be particularly useful when the symbolic constants LOWER, UPPER and STEP appear in several places in your file because:
- if the value does change for some reason you only have to change it in one place, e.g. your #define.
- it gives the value a meaningful name that conveys its purpose to the reader.
Does that help?