< previous page page_34 next page >

Page 34
Analysis: Line 2 includes the required include statement for the iostream's library so that cout will work. Line 4 begins the program.
On line 6, Width is defined as an integer, and its value is initialized to 5. Another integer, Length, is also defined, but it's not initialized. On line 7 the value 10 is assigned to Length.
On line 10 an integer, Area, is defined, and it is initialized with the value obtained by multiplying Width times Length. On lines 12 through 15 the values of the variables are printed to the screen. Note that the special word endl creates a new line.
endl stands for end line and is end-ell rather than end-one. It is commonly pronounced end-ell.

typedef
New Term: It can become tedious, repetitious, and, most important, error-prone to keep writing unsigned short int. C++ enables you to create an alias for this phrase by using the keyword typedef, which stands for type definition.
In effect, you are creating a synonym, and it is important to distinguish this from creating a new type (which you will do on Day 6, Basic Classes). typedef is used by writing the keyword typedef followed by the existing type and then the new name. For example,
typedef unsigned short int USHORT
creates the new name USHORT that you can use anywhere you might have written unsigned short int. Listing 3.3 is a replay of Listing 3.2 using the type definition USHORT rather than unsigned short int.
LISTING 3.3 DEMONSTRATEStypedef

d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
1:    // *****************
2:    // Demonstrates typedef keyword
3:    #include <iostream.h>
4:
5:    typedef unsigned short int USHORT;       //typedef defined
6:
7:    int main()
8:    {
9:       USHORT Width = 5;
10:      USHORT Length;
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_34 next page >

If you like this book, buy it!