Using the #define statement
Lines 3 and line 4 of the program contain the #define statement. The #define
statement defines a name for a particular string of characters. In the above program,
“#define STR ‘0’ “ tells the computer that anytime it comes across the name “STR”, it
should replace it with the character “0”. Likewise, “#define END ‘Z’ “ tells the
computer that the name “END” is to be replaced by the character ‘Z’.
The reason for using a #define statement is to make the program easier to read and
to change later. If, in the above program, we used the character ‘0’ a number of times
throughout the program and we wished to change all of them to ‘A’, it would be much
easier to change the #define statement once, rather than making multiple changes.
Incrementing and decrementing
The program here establishes the initial value for trhe variable “ch” as “0”, and tells it
to keep repeating the loop “while (ch<=END)”, in which END is the name that
represents the character “Z”. As long as “ch” is less than or equal to “Z”, the following
printf() statement is executed, and then the getchar() statement is executed.
This program does not really require input of any characters, but if we did not include
a getchar() statement here, the data produced by this program would simply scroll
across the display so quickly that we would not be able to use it. The getchar()
statement causes the computer to stop here and wait for input, so that you can read
the last line produced by the program. When you are ready to continue, simply press
the . . key.
Once execution continues past the “ch++;” statement, 1 is added to the value of “ch”.
“++” is called the increment operator. The following table shows how it is used, as
well as its opposite, the decrement operator.