Cpp - Data Type Integral types

Introduction

Type
Size
Range of Values (decimal)
char
1 byte
-128 to +127 or 0 to 255
unsigned char
1 byte
0 to 255
signed char
1 byte
-128 to +127
int

2 byte resp.
4 byte
-32768 to +32767 resp.
-2147483648 to +2147483647
unsigned int

2 byte resp.
4 byte
0 to 65535 resp.
0 to 4294967295
short
2 byte
-32768 to +32767
unsigned short
2 byte
0 to 65535
long
4 byte
-2147483648 to +2147483647
unsigned long
4 byte
0 to 4294967295

Demo

#include <iostream> 
#include <climits>       // Definition of INT_MIN, ... 
using namespace std; 

int main() //w ww .  j ava 2  s . c o  m
{ 
   cout << "Range of types int and unsigned int" 
          << endl << endl; 
   cout << "Type             Minimum           Maximum" 
          << endl 
          << "--------------------------------------------" 
          << endl; 

   cout << "int            " <<  INT_MIN << "        " 
                                       <<  INT_MAX << endl; 

   cout << "unsigned int   " <<  "          0        " 
                                       << UINT_MAX << endl; 
   return 0; 
}

Result

Related Topics

Exercise