CS 150 Introduction to C++ Programming - Spring 1998 |
---|
[ Home | Lecture Notes| WebTutor | WebTutor Site Map]
C++ supports two basic number types:
There are variations of these numbers to get bigger or smaller versions.
Mostly you will just use "int" and "float"
as appropriate.
Floating point and integer numbers have different rules for thier
arithmetic.
In particular dividing an integer by an integer produces an
integer (called integer divide ) by simply removing the part after the decimal
point (called truncating to an integer). Also
integers have a way of producing the remainder of the division as
a integer called the modulus operator (written
as "%"). This operator does not work for floats. (see
tutor page on evaluating expressions for
more examples)
It is possible to mix integers and floating points numbers.
Such expressions are called mixed type or mixed
mode expressions. In such cases, all numbers are
converted to floating point number and the result is a floating
point number. Such a conversion is called implicit
since it is done automatically.
You can also force a conversions to occur explicitly
by using a type cast operator. (pp. 97-98).
This exercise tests your understanding of mixed mode expressions.