Wednesday, 20 November 2013

Data Types in C++


Data Types
It defines the set of values and set of operations on those values. The data and its types are defined before designing the actual program to process the data.
A c++ program may need to process different types of data. Each data type require different amount of memory. C++ language provides the following data types.
Int                                          to store numeric values
Float                                      to store real values
Double                 to store large real values
Char                                       to store character values
Integer Data Types
Integer data is numeric value with no decimal point or fraction. It includes both positive and negative values. The minus sign – is used to indicate negative value. If no sign is used, the value is positive by default. E.g. 90, 3, -3, etc.
Types of integers
C++ provides the following types of integer data types
Data Type
Size in Bytes
Ranges
Int
2
-32768 to 32767
Short
2
-32768 to 32767
Unsigned int
2
0 to 65535
Long
4
-2,14,74,83,648 to 2,14,74,83,647
Unsigned long
4
O to 4,29,49,67,295

Real Data Types
Real data is numeric value with decimal or fraction. It is also called floating point number. It includes both positive and negative values. The minus sign – is used to indicate negative value. If no sign is used, the value is positive by default. E.g. 10.0, 3.4, -10.9 etc.
C++ provides the following real data types.
Data Type
Size in Bytes
Ranges
Float
4
3.4 × 10-38 to 3.4 × 1038
Double
8
1.7 × 10-308 to 3.4 × 10308
Long double
10
1.7 × 10-4932 to 1.7 × 104932

Character Data Type
Char data type is used to store character value. It takes 1 byte in memory. It is used to represent a letter, number or punctuation mark and few other symbols. These values are normally given in single quotes. E.g. ‘3’, ‘#’, ‘y’, ‘Y’. it is possible to perform mathematical operation on character values. The characters can be added, subtracted and compared like numbers.