Program to find Size of Data Types in C++

Notes:

Program to find Size of Data Types in C++ Programming Language :
- Data type indicates type of data
- Data type also indicates the amount of memory to be allocated for a specific type of data

- W.K.T. There are 7 primitive data types available in C++ language
1. int : 4 or 2 bytes
2. float : 4 bytes
3. double : 8 bytes
4. char : 1 byte
5. wchar_t : 2 bytes
6. bool : 1 byte
7. void : 1 or 0 byte

We can display size of any data type using sizeof special operator

int sizeof(data type / data value / data) :
-returns the amount of memory being allocated for given data type, data value or data in bytes

Example Code:

#include <iostream>
using namespace std;

int main()
{
cout << "Size of int =" << sizeof(int) << " bytes" << endl;
cout << "Size of float =" << sizeof(float) << " bytes" << endl;
cout << "Size of double =" << sizeof(double) << " bytes" << endl;
cout << "Size of char =" << sizeof(char) << " byte" << endl;
cout << "Size of wchar_t =" << sizeof(wchar_t) << " bytes" << endl;
cout << "Size of bool =" << sizeof(bool) << " byte" << endl;
cout << "Size of void =" << sizeof(void) << " byte" << endl;
cout << endl;
cout << "Size of 22 =" << sizeof(22) << " bytes" << endl;
cout << "Size of (float) 3.142 =" << sizeof((float)3.142) << " bytes" << endl;
cout << "Size of 3.142 =" << sizeof(3.142) << " bytes" << endl;
cout << "Size of 'A' =" << sizeof('A') << " byte" << endl;
cout << "Size of (wchar_t)'A' =" << sizeof((wchar_t)'A') << " bytes" << endl;
cout << "Size of true =" << sizeof(true) << " byte" << endl;
return 0;
}