2.5 Memory Concepts
Variable names such as number1
, number2
and sum
actually correspond to locations in the computer’s memory. Every variable has a name, a type, a size and a value.
In the addition program of Fig. 2.5, when the statement in line 13
std::cin >> number1; // read first integer from user into number1
is executed, the integer typed by the user is placed into a memory location to which the name number1
has been assigned by the compiler. Suppose the user enters 45
for number1
. The computer will place 45
into the location number1
, as shown in Fig. 2.6. When a value is placed in a memory location, the value overwrites the previous value in that location; thus, placing a new value into a memory location is said to be a destructive
Get C++ How to Program, 10/e 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.