Write a program to print correct memory size of different data types of C++ language 

In this program, we want to know the memory size of every data types considered. Here, we use a special operator like sizeof() which further tell us about the memory size of the data type.

#include <iostream>
using namespace std;
int main() 
{
 cout << "Size of short int data type is " << sizeof(short int)<< endl;

 cout << "Size of int data type is " << sizeof(int)<<endl;
 cout << "Size of long int data type is " << sizeof(long int)<< endl;
 cout << "Size of char data type is " << sizeof(char)<<endl;
 cout << "Size of float data type is " << sizeof(float)<<endl;
 cout << "Size of double data type is " << sizeof(double)<<endl;
 cout << "Size of wchar_t data type is " << sizeof(wchar_t)<< endl;
 return 0;
}

Program output is tested on www.jdoodle.com

Size of short int data type is : 2
Size of int data type is : 4
Size of long int data type is : 8
Size of char data type is : 1
Size of float data type is : 4
Size of double data type is : 8
Size of wchar_t data type is : 4

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: