August 2001
Beginner
482 pages
10h 52m
English
You assign a value to a variable by using the assignment operator (=). Thus, you would assign 5 to Width by writing
unsigned short Width; Width = 5;
You can combine these steps and initialize Width when you define it by writing
unsigned short Width = 5;
Initialization looks very much like assignment, and with integer variables, the difference is minor. Later, when constants are covered, you will see that some values must be initialized because they cannot be assigned a value.
Listing 3.2 shows a complete program, ready to compile, that computes the area of a rectangle and writes the answer to the screen.
0: // Demonstration of variables 1: #include <iostream> ... |
Read now
Unlock full access