-a variable is a named memory location which stores a value

--to use a variable in a program, it must be defined by giving it a type and identifier

eg: double Radius

Once defined the variable must be given a value

eg: Radius = 12.3 ;
the = sign is similar to the := in Pascal which means that the value is assigned to the variable

Using Named Constants

-defined in a statement and begins with the word "const"

--this is used to define a constant: in math Pi is a constant value (3.14159) represent this in C++, you do the following:

const double PI = 3.14 ;

--a constant is used to represent a value that does not change during the execution of a program

Choosing Identifiers

Rules for choosing identifiers:

Built in Data Types

1. double

2. int and long

3. char:

Example: char Ch:

Ch = 'A';


displays : A


VARIABLES can be defined in single statements or in multiple variables in one line

example: int x,y,z

Char ch1,ch2

Expressions and Operators

-built in arithmetic operations include: (*) multiplication,

(+) addition, (-) subtraction, and ( / ) division

Promotion: numeric values of various types can be mixed in an expression: an expression involving two doubles, results in a double, however, whenever an integer and a double are used, C++ promotes the value with the narrow range to the value with the wider range: integer becomes a double: this avoids the problem known in Pascal as "type mismatch"

Integer Division: if you divide two integers, the resulting number will be truncated, or the decimals will be cut off!

Type Casting: when real division is done, type casting converts one of the values into a real number

Modulus Division: represented by %, Modulus division returns the remainder....similar to MOD in Pascal

Operator Precedence: same as order of operations in mathematics

Output Formatting

Defining Variables and Type Casting: More Details

Click to Visit