Data types describe the kind of data so that computer can store or manipulate them appropriately. This is the reason to declare a data type in C++ programming.
Data types are also necessary because data items such as numbers are used in expressions. If there is a mismatch, for example – integer and real numbers – in an expression then the computer must be able to resolve it. C++ allows the following data types.
- Integer
- Float
- Double
- Char
Memory Organization
All data is stored in memory which is organized in bytes. A single byte is of
The integer data type takes
Integer Data Types
The integers are negative and positive numbers. C++ add modifiers like
- int
- long int
- short int
- signed int
- unsigned int
For example
short int = 2 bytes = 16 bits
The integers have both positive and negative values and each bit position takes two values –
Therefore, its range is
The
An Example Program
// Program to display the size of integer data types
#include <iostream.h>
int main()
{
int a = 10;
short int b = 12;
long int c = 100;
unsigned int d = 30;
signed int e = 32;
cout << sizeof(a) << "Bytes" << endl;
cout << sizeof(b) << "Bytes" << endl;
cout << sizeof(c) << "Bytes" << endl;
cout << sizeof(d) << "Bytes" << endl;
cout << sizeof(e) << "Bytes" << endl;
system("pause");
return 0;
}
Output
4 Bytes
2 Bytes
4 Bytes
4 Bytes
4 Bytes
The