Data types In c++:
Computer is of various types. It may include integers, characters, string etc.
Types of Datatypes:
1.Integers
2.Characters
3.Strings
4.Floating point type
1.Integers:
Integers are whole number such as 7, 12, 27, -7, -12, -27 etc. No fraction as part is used in integers.
Integers are generally constants. Range of values is -215 to 215 -1
(ie.-32768 to 32768)
It also Divide into sub-types
i.Unsigned integers ii.Short integers iii.Long integers
i.Unsigned Integers:
Unsigned integers are those non negative whose values varies from 0 to 65535. if we have to use a value of 32770, we have to use unsigned integers because ordinary integer provide a value to 0 maximum 32767.
ii.Short Integers:
Short integers are those integers having small range of value. The value of this integer varies between -123 to 127. This type of integers take lesser space for storage.
iii.Long Integers:
Long integers are having wide range of value. The values varies between – 129467290 to 429467295.
Data Type
Size Bits
Range
Integers
16 Bits
– 215 to 215–1
(32768 to 32768)
Unsigned integers
16 Bits
0 to 216 – 1
(0 to 65535)
Short integers
8 Bits
– 27 to 27 – 1
(– 128 to 127)
Long integers
32 Bits
– 232 – 232 – 1
– 4294967296 to 4294967295
2.Character Types:
Character (char) Types are one Byte size and character constant varies between 0 to 255. The characters are stored the computer memory as integers. Binary form. Each character is assigned a particular value according to ASCII codes [ ASCII means – American standard code for information Interchange ] A table of ASCII codes has been provided at the end of the book. It’s worth noting that no computer language can use more than 256 characters [A to Z, numbers, punctuation marks etc], these, character are assigned coding from 0 -255.
It also Divide into sub-types
i.char
ii.Unsigned char
iii.Signe char
Characters types
Size
Rank
char
1 Byte
-27 to 27-1
(-128 to 127)
Unsigned Char
1 Byte
0 to 28-1
( 0 to 255)
Signed char
1 Byte
-27 to -27-1
( -128 to 127)
Character can be written by writing the character in single quotes. But some characters are written in C + + program by using Escape, carriage Return, Tab characters C++ compiler recognized these characters for formatting.
Escape character ( ) Changes the meaning of the character which Follows it, e.g. The character b indicates the letter b when its preceded by escape character, it means Back space.
Character Meaning
n New line
t Horizontal Tab
v Vertical Tab
b Back space
\ Back slash
” Double Quotes
’ Single Quote
? Question mark
3.String:
String is a series of characters. The string is enclosed within double quotes. A string is used to write or store messages.
“HELLO”
The “HELLO” is string and the characters of string are stored in sequential location.
H
E
L
L
O
Φ Null character
The null character is added at the end of string automatically by the compiler.
Floating point constant(Float data type):
A floating point constant may bear +ve or –ve sign. In case of no signed is used, the number is treated as positive. Decimal is number refer that is floating number. Floating form A provides greater range of integers between –ve or +ve.
Type of Float Data types:
i.Float
ii.Double
ii.Long Double
Type
Size
Range
float
4 Bytes
3.4*10-38 + 03.4*1038
double
8 Bytes
1.4*10-308 + 01.7*10308
long double
10 Bytes
3.4*10-4932 to .4*104932.
Some valid floating point constant:
5.0 (with Decimal)
+ 0 . 1832 (With +ve signed)
–12 . 18 (with – ve signed)
Invalid floating point constant
1000 ( Decimal Missing )
h (fractional portion is absent)
+ 20.123 (Both signed not allowed)
+ 20.123 (Blank space after +ve signed not allowed)
– 20.123 (Blank space after –ve signed not allowed)
20, 23.1516 (comma not allowed)
20, 23. 1516 ( Blank space bet digits not allowed)
Floating point constants written in this form are called to be in exponent form (B). notation. This notation is also called standard form.
Standard form
91360000 9.136 * 106
0.9136 9.136 * 10–1
0.00009136 9.136 * 10-5
Representation in exponent form C + +
9.136 * 106 can written as 9.136 E 6
9.136 * 10–6 can written as 9.136 E –6
9.136 * 106 can be written as 9.136 + 6
9.136 y 106 can be written as 9.136 E 06
E
Left Part Right part
Left part is called Mantissa Right part is call Exponent 9. 136 E is invalid notation because exponent is absent.
E 6 is invalid notation because Mantissa is absent.
Double Data Type occupied double memory than that of float number with much larger range.