Title: Constants
Course: CPS 120: Introduction to Computer Science ~ Master (Aug/2015) OLD > Section: Learning Units

Visual C++ constants

- Defines a place in memory to hold a value.
- Is similar to a variable but its value cannot be changed while a program is running.
- Enables a value to be assigned a name which makes code easier to read.
- Enables a value, which may be used in many places in a program, to be changed in one place before the program runs.

Constant declaration

- Usually appears near the top of a program.
- Defines the name, type, and value of a constant.
- Data type of value must match type.
- Has the form:
const type identifier = value;

const declaration examples:

const declaration examples
const int Year = 2001; | Declares a constant named Year to hold integer value 2001.
const double Rate = 0.06; | Declares a constant named Rate to hold double value 0.06.
const string City = “Mio”; | Declares a constant named City to hold string value “Mio”.