Casio FX-890P Owner's Manual page 95

Casio personal computer owner's manual
Table of Contents

Advertisement

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.
Operator Example Meaning
++
++i
--
--i
++
i++
--
i--
As you can see here, the increment and decrement operators can be used either
before or after the value, with different results. For other useful operators, see page
108 of this manual.
Increment i by 1 and use the value.
Decrement i by 1 and use the value.
Use i and then increment it by 1.
Use i and then decrement it by 1.
95

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Z-1grZ-1

Table of Contents