What is Data Types?
All variables use
data-type during declaration to restrict the type of data to be stored. Some
memory occupied by compiler that variable based on the data-type with which it
is declared. Every data type have different amount of memory..
C++ Data Types chart with size and range.
Variable Type
|
Variable Size in Byte
|
Range
|
int
|
4 bytes
|
-2147483648 to 2147483647
|
unsigned int
|
4 bytes
|
0 to 4294967295
|
signed int
|
4 bytes
|
-2147483648 to 2147483647
|
short int
|
2 bytes
|
-32768 to 32767
|
unsigned short int
|
2 bytes
|
0 to 65,535
|
signed short int
|
2 bytes
|
-32768 to 32767
|
long int
|
4 bytes
|
-2,147,483,648 to 2,147,483,647
|
signed long int
|
4 bytes
|
same as long int
|
unsigned long int
|
4 bytes
|
0 to 4,294,967,295
|
float
|
4 bytes
|
+/- 3.4e +/- 38 (~7 digits)
|
double
|
8 bytes
|
+/- 1.7e +/- 308 (~15 digits)
|
long double
|
8 bytes
|
+/- 1.7e +/- 308 (~15 digits)
|
wchar_t
|
2 or 4 bytes
|
1 wide character
|
char
|
1 byte
|
-127 to 127 or 0 to 255
|
unsigned char
|
1 byte
|
0 to 255
|
signed char
|
1 byte
|
-127 to 127
|
The size of variables
might be different from those shown in the above table, depending on the PC and
the PC you are using. Following is the example, which will produce correct size
of various data types on your system. we can use sizeof(data type) for finding size in coding.
#include <iostream> //
header
using namespace
std; // including namespace std
int main()// main
{
// output int size
cout << "Size of int = " << sizeof(int) << endl;
// output char size
cout << "Size of char = " << sizeof(char) <<
endl;
// output float size
// output float size
cout << "Size of float = " << sizeof(float) <<
endl;
// output double size
// output double size
cout << "Size of double = " << sizeof(double) <<
endl;
return 0;
No comments:
Post a Comment