C++ Data Types

C++ is rich in its data types. Data types specifies a particular kind of data item defined by the values it can take. Data types in C++ can be classified into the following:

  1. Built-in Data Types
  2. User Defined Data Types
  3. Derived Data Types


Built-in Data Types

C++ supports various built-in data types. They are given below in the table:

Type Storage size Value range
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 4 bytes -2,147,483,648 to 2,147,483,647
unsigned int 4 bytes 0 to 4,294,967,295
signed int 4 bytes -2147483648 to 2147483647
short int 2 bytes -32768 to 32767
unsigned short int 2 bytes 0 to 65,535
signed short int 2 bytes -32768 to 32767
long int 8 bytes -2,147,483,648 to 2,147,483,647
unsigned long int 8 bytes 0 to 4,294,967,295
signed long int 8 bytes -2,147,483,648 to 2,147,483,647
float 4 bytes 3.4E-38 to 3.4E+38
double 8 bytes 1.7E-308 to 1.7E+308
long double 10 bytes 3.4E-4932 to 1.1E+4932

Another built-in data type is void. Two uses of void are to specify the return type of a function when it is not returning any value and to indicate an empty argument list to a function.



User Defined Data Types

There are three types of user defined data types.

Data Types Description
Structures and class We described struct as user-defined data type in C. These data type also legal in C++, some more features have been added to make them suitable for object oriented programming. C++ also permits to define another user-defined data type known as class. It can be used any other basic data type to declare variables. The class variables are known as objects which are the main focus of the object-oriented programming.
Enumerated Enumeration is another user-defined data type which provides a way for attaching names to number. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2 and so on. This facility provides an alternative means for creating symbolic constants.

Derived Data Types

There are three types of derived data types in C++.

Data Types Description
Arrays An array is used for storing a collection of data. Arrays in C++ is similar to C. The only exception is the way character arrays are initialized.
Functions Functions have undergone major changes in C++. While some of these changes are simple others require a new way of thinking when organizing a program.
Pointers Pointers are used to access the memory and deal with their addresses.