Simple Variables
Programs typically need to store information—perhaps the current price of IBM stock, the average humidity in New York City in August, the most common letter in the Constitution and its relative frequency, or the number of available Elvis imitators. To store an item of information in a computer, the program must keep track of three fundamental properties:
Where the information is stored
What value is kept there
What kind of information is stored
The strategy the examples have been using so far is to declare a variable. The type used in the declaration describes the kind of information, and the variable name represents the value symbolically. For example, suppose Chief Lab Assistant Igor uses the following statements:
int braincount; ...
Get C++ Primer Plus, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.