Data Types cont.....

Floating point (float):

Floating point variables are used to store real numbers(numbers involving decimals). The range of floating point type is from 3.4 x 10^-38 to 3.4 x 10^38 and the size is 4 bytes. Type float provides approx. 7 digits of precision. Three types of floats are used in C++: Float, Double, Long Double. A floating point number can be represented in two forms: decimal form and exponent form.

Examples of Decimal form: 250.46, -1738.72, 8.39

Examples of Invalid Float: 16,433.67 (comma used), -84 (no decimal point)

Examples of Exponent Form:

52940000 -- 5.294 x 10^6

0.8731 -- 8.731 x 10^-1

0.4269 -- 4.269 x 10-8

Examples of Valid Forms

4.321 x 10^6 = 4.321E6

= 4.321E+6

= 4.321E06

4.321 x 10^-6 = 4.321E-6

The part to the left of E is known as the Mantissa.

The part to the right of E is known as the Exponent.

Examples of Invalid Forms : 4.321E (exponent absent), E6 (mantissa absent)

Double

Double data type is used to represent double precision floating point numbers. It is known as a double data type as it accupies twice the memory than that of floating point type. The size is 8 bytes. Type double provides approx. 15 digits of precision. Long double floating data type has a higher range. The size is 10 bytes and provides approx. 19 digits of precision.

Character (char)

This is a data type large enough to hold a single ASCII character. There are a maximum of 256 characters in the C++ character set. It is usually one bye in size. Examples are small integers such as 42 and characters such as 'Z'. Type char is used to store sharacter strings. Its types are: signed char, unsigned char, and char.

Signed Char

Signed char data type accepts both negative and positive values. the range of the signed char is from -128 to +127 and the size is 1 byte.

Unsigned Char

Unsigned char data type accepts only zero and positive values. The range of unsigned char is from 0 to 255 and the size is 1 byte.

Char

Char is the default form of the character data type. It is usually the same as an unsigned char. the range of char is from -128 to +127 and the size is 1 byte.

Examples of the char data type are: 'R' , '7' , 'S'

Strings

A string is a combination of characters. It is enclosed within double quotes. All the characters of a string can be stored in sequential locations in the memory.

"COMPUTER" is a string. It will be stored in memory as shown here.

* The compiler adds a character at the end of the string. This character is known as null character.

* The null charater denotes the terminatin point for a string.

HOME LEARN C++ PREVIOUS NEXT