Data Types in C++

Each variable has an associated data type in C++ programming. C++ supports both signed and unsigned literals and requires different amounts of memory.

Basic Data Types

Type Specifier Description
int Stores an integer number
long int Stores a long integer numbers
unsigned int Stores an unsigned integer numbers
char Store a character
unsigned char Store a unsigned character
float Stores a floating number
Double Stores a double floating number
long double Stores a long double floating number

Variable

Variable is a location in computer memory where data is temporary stored OR saved.

How to use

e.g: int RollNumber = 13;

Explanation
int is Data Type of variable
RollNumber is Name of variable
13 is Value of variable

Another Example

e.g: float floatingVariable = 5.67;

Explanation
float is Data Type of variable
floatingVariable is Name of variable
5.67 is Value of variable

Difference between variable Declaration, Definition and Initialization
Variable Declaration:

int MyVariable;

Variable Definition:

MyVariable = 56;

Variable Initialization:

int MyVariable = 56;


Data Types
Type Typical Byte Width Typical Range
char 1 byte -127 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -127 to 127
int 4 bytes -2147483648 to 2147483647
unsigned int 4 bytes 0 to 4294967295
signed int 4 bytes -2147483648 to 2147483647
short int 2 bytes -32768 to 32767
unsigned short int Range 0 to 65,535
signed short int Range -32768 to 32767
long int 4 bytes -2,147,483,647 to 2,147,483,647
signed long int 4 bytes same as long int
unsigned long int 4 bytes 0 to 4,294,967,295
float 4 bytes +/- 3.4e +/- 38 (~7 digits)
double 8 bytes +/- 1.7e +/- 308 (~15 digits)
long double 8 bytes +/- 1.7e +/- 308 (~15 digits)
wchar_t 2 or 4 bytes 1 wide character

Special Characters
Character Use for ASCII
\n OR endl Newline 10
\t Horizontal tab 9
\v Vertical tab 11
\b Backspace 8
\r Carriage return 13
\f Formfeed 12
\a Alert 7
\\ Backslash 92
\? Question mark 63
\' Single quotation mark 39
\" Double quotation mark 34
\ooo Octal number --
\xhhh Hexadecimal number --
\0 Null character 0