Introduction to Programming in C++
Seventh Edition
Chapter 3:
Variables and Constants• Distinguish among a variable, a named constant, and a
literal constant
• Explain how data is stored in memory
• Select an appro
...
Introduction to Programming in C++
Seventh Edition
Chapter 3:
Variables and Constants• Distinguish among a variable, a named constant, and a
literal constant
• Explain how data is stored in memory
• Select an appropriate name, data type, and initial value
for a memory location
• Declare a memory location in C++
An Introduction to Programming with C++, Seventh Edition
Chapter Objectives
2• After Step 3, programmer has an algorithm and has
desk-checked it
• The fourth step in the process is coding the algorithm
into a program
• The step begins by assigning a descriptive name, data
type, and (optionally) initial value to each unique input,
processing, and output item in the IPO chart
• These are used to store the item in the computer’s
internal memory
An Introduction to Programming with C++, Seventh Edition
Beginning Step 4 in the ProblemSolving Process
3• Computer’s internal memory is composed of memory
locations, each with a unique numeric address
• Similar to collection of storage bins
• Each address can store one item at a time
• Address can contain numbers, text, or program
instructions
• To use a memory location, programmer must reserve
the address, called declaring
An Introduction to Programming with C++, Seventh Edition
Internal Memory
4• Declaring a memory location is done with an instruction
that assigns a name, data type, and (optional) initial
value
• The name allows the programmer to refer to the
memory location elsewhere in the program using a
descriptive word, rather than the numeric address
• The data type indicates what type of information the
address will store (e.g., number or text)
An Introduction to Programming with C++, Seventh Edition
Internal Memory (cont’d.)
5• Two types of memory locations can be declared:
variables and named constants
• Variables are memory locations whose values can
change during runtime (when the program is running)
• Most memory locations are variables
• Named constants are memory locations whose values
cannot change during program execution
An Introduction to Programming with C++, Seventh Edition
Internal Memory (cont’d.)
6An Introduction to Programming with C++, Seventh Edition
Internal Memory (cont’d.)
Figure 3-1 Illustration of storage bins
7• Name (identifier) assigned to a memory location should
be descriptive
• Should help t
[Show More]