C++ Data type

Data type in every language is very important. Data type means the different kind of data which are supported by a particular programming language.

C++ programming language supports various kinds of data types. C++ data types are broadly classified into three categories.

  1. Built-in data types.
  2. Derived data types.
  3. User defined data types.

C++ Built-in Data Types:

  • int
  • char
  • void
  • float
  • double

C++ Derived Data Types:

  • array
  • function
  • pointer
  • reference

C++ User Defined Data Types:

  • structure
  • union
  • class
  • enumeration

Detail Description Of Different Data Types

Character Data Types:

Data Types Size Range Description
char 1 byte -128 to 127 or 0 to 255 Contain single character. It may include a letter, a digit, a punctuation mark, or a space.
signed char 1 byte -128 to 127 Signed character.
unsigned char 1 byte 0 to 255 Unsigned character.
wchar_t 2 or 4 bytes 1 wide character Wide character.

Integer Data Types:

Data Types Size Range Description
int 4 bytes -2147483648 to 2147483647 Integer.
signed int 4 bytes -2147483648 to 2147483647 Signed integer.
unsigned int 4 bytes 0 to 4294967295 Unsigned integer
short 2 bytes 2 bytes Short integer.
signed short 2 bytes -32768 to 32767 Signed short integer.
unsigned short 2 bytes 0 to 65535 Unsigned short integer
long 4 bytes -2147483648 to 2147483647 Long integer.
signed long 4 bytes -2147483648 to 2147483647 Signed long integer.
unsigned long 4 bytes 0 to 4294967295 Unsigned long integer.

Unsigned long integer.

Data Types Size Range Description
float 4 bytes +/- 3.4e +/- 38 (~7 digits) Floating point number.
double 8 bytes +/- 1.7e +/- 308 (~15 digits) Double precision floating point number.
long double 8 bytes +/- 1.7e +/- 308 (~15 digits) Long double precision floating point number.

Boolean Data Type:

Data Types Size Range Description
bool 1 byte true or false It takes only one value either true or false

Enumeration Data Types:

Enumeration is users define data types having set of enumeration constants. The ‘enum’ keyword is used to create enumeration data type.

Syntax:

Typedef Data Types:

Typedef data type is used to create new data type. It facilitates to use the existing data type with different name.

Syntax:

Example: