Data Types in C++
- Data may be variables or constants. They must be declared before they
can be used. Declarations have the following form...
- <data type> indentifier_list;e.g.,
int x, y; //declares identifiers x and y as integers
const float PI = 3.14; //declares and initializes a float constant named PI
- Identifiers can be upto 127 characters long, must begin with a letter, must consist of
letters, numbers, and underscores only, and must not use
reserved
words
- C++ Supports the following simple types of data:
Simple Data Types
- char
- The smallest data type, usually require 1 byte of storage. Assume single character
values.
- int
- These data types assume integer values. There are three types of integers - long ,
int, short. Long integers require the largest amount of storage of the three, and
short integers require the least amount of storage. Many compilers treat short integers
and integers as the same, whereas some other compilers do not distinguish between long
integers and integers.
- enum
- They are stored internally as integer values, but are used in programs to represent
categorical data. They are not used in arithmetic operations.
- float
- Assume rational number values i.e.,the number values have an integer part and a
fractional part. They usually require the same amount of storage as integers
- double
- Assume rational number values, however, they provide a higher degree of precision than float
data types. They exist in two forms: long double, and double. Long
double data types provide a higher degree of precision than double data types, however
they also require more storage.
- In addition C++ supports complex types of data such as arrays, structs, unions,
and classes. C++ also supports two other special data types - pointers
and references. These data types will be discussed later
Back to Previous Page
Document:
Local Date:
Last Modified On: