C++ Types

C++ types are substantially the same as in C. All data has an associated type, which tells:

Different Data Types

char short int long

Writing Integer Values

An integer is a sequence of digits with optional leading sign. There is no leading 0 unless we want just 0. Commas should also be omitted when establishing integer values.

Floating Data Types

Some floating data types are:

float double long double

Some things to note about writing floating values!!

Since float and double are so much more flexible, why use integer types at all? First of all, integers are quicker to use than floats because of the brevity of internal representation, but they are not capable of giving the amount of precision that a float can offer. So it is a trade-off between speed and expressive power. See Demo Precision.cpp

Some things to note about writing char values!!

Variables

Variables are names by which you store and retrieve data. The rules for creating variables are:

Declaration Examples

int rocky, Bullwinkle;
double Agent007, James_Bond;

Declarations do 2 things:
  1. Creates a place to put the variables and gives a name to it.
  2. Says what kind (type) of value you'll find there.

Other variable stuff

To Index Previous Next