Find size and storage capacity of primitive data types source code

This snippet submitted by Ali Nawkhas Murad on 2011-12-29. It has been viewed 22102 times.
Rating of 5.4 with 152 votes

// This simple program shows the size and ability of primitive data types to handle minimum and maximum values, to take care about it, while you write a program.

#include <iostream>
#include <climits>
#include <cstdlib>

using namespace std;
int main()
{
   cout<<"Size of char = "<< sizeof(char)<<" bytes \n"
       <<"Minimum number of char data type = "<<CHAR_MIN<<" value \n"
       <<"Maximum number of char data type = "<<CHAR_MAX<<" Value \n"
       <<"Maximum number of unsigned char data type = "<<UCHAR_MAX<<" Value \n";

   cout<<"\nSize of short int = "<< sizeof(short int)<<" bytes \n"
       <<"Minimum number of short data type = "<<SHRT_MIN<<" value \n"
       <<"Maximum number of short data type = "<<SHRT_MAX<<" Value \n"
       <<"Maximum number of unsigned short data type = "<<USHRT_MAX<<" Value \n";

   cout<<"\nSize of int = "<< sizeof(int)<<"bytes \n"
       <<"Minimum number of int data type = "<<INT_MIN<<" value \n"
       <<"Maximum number of int data type = "<<INT_MAX<<" Value \n"
       <<"Maximum number of unsigned int data type = "<<UINT_MAX<<" Value \n";

   cout<<"\nSize of long = "<< sizeof(long int)<<"bytes \n"
       <<"Minimum number of long data type = "<<LONG_MIN<<" value \n"
       <<"Maximum number of long data type = "<<LONG_MAX<<" Value \n"
       <<"Maximum number of unsigned long data type = "<<ULONG_MAX<<" Value \n";

   cout<<"\nSize of float = "<< sizeof(float)<<" bytes \n";
   cout<<"\nSize of double = "<< sizeof(double)<<" bytes \n";
   cout<<"\nSize of long double = "<< sizeof(long double)<<" bytes \n";

   cout<<"\nASCII code of 0 = "<<int('0')<<"... and code of 9 ="<<int('9')<<endl;
   cout<<"ASCII code of \"A\" = "<<int('A')<<"... and code of \"Z\" ="<<int('Z')<<endl;
   cout<<"ASCII code of \"a\" = "<<int('a')<<"... and code of \"z\" ="<<int('z')<<"\n";
    return 0;
}




More C and C++ source code snippets