C++: Signed and Unsigned data types

 
Name Description Size Range
char Character or small integer. 1byte signed: -128 to 127
unsigned: 0 to 255
short int (short) Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool true or false. 1byte true or false
float Floating point number. 4bytes 3.4e +/- 38 (7 digits)
double Double precision floating point number. 8bytes 1.7e +/- 308 (15 digits)
long double Long double precision floating point number. 8bytes 1.7e +/- 308 (15 digits)
wchar_t Wide character. 2bytes 1 wide character
Signed and unsigned explained

Unsigned takes only positive values from zero to up.

Where as signed takes both negative and positive values.

Example of overflow

#include <iostream>
#include <string>
#include <climits>
using namespace std;
//variable_4.cpp
//unsigned 2147483647
int main()
{
//---------------------
cout << "int has " << sizeof(int) << " bytes.\n";
cout << "Minimum int value = " << INT_MIN << "\n";
cout << "Maximum int value = " << INT_MAX << "\n";

//----------------------
int n2 = 3245678932;
unsigned int n3 = 3245678932;
cout <<"Integers " << n2 << " --unsigned- " << n3;

return 0;
}