DATA TYPES IN C++ | Built-in, Derived, User Defined Data Types

In C++ programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them. The amount of memory required to store a single number is not the same as required by a single letter or a large number. Further, interpretation of different data is different inside computers memory. 

The memory in computer system is organized in bits and bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer. In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers. 

Data Type in C++ is used to define the type of data that identifiers accepts in programming and operators are used to perform a special task such as addition, multiplication, subtraction, and division etc of two or more operands during programming. 

C++ supports a large number of data types. The built in or basic data types supported by C++ are integer, floating point and character type. A brief discussion on these types is shown in Figure 2.3 which are shown below:

Data Type in C++

Built-in Data Types 

There are four types of built-in data types as shown in the fig: 2. Let us discuss each of these and the range of values accepted by them one by one. 

Integer Data type (int) 

An integer is an integral whole number without a decimal point. These numbers are used for counting. For example 26, 373, -1729 are valid integers. Normally an integer can hold numbers from -32768 to 32767. 

The int data type can be further categorized into following: 

  • Short 
  • Long 
  • Unsigned

The short int data type is used to store integer with a range of – 32768 to 32767, However, if the need be, a long integer (long int) can also be used to hold integers from -2, 147, 483, 648 to 2, 147, 483, 648. The unsigned int can have only positive integers and its range lies up to 65536.

Floating point data type (float)

A floating point number has a decimal point. Even if it has an integral value, it must include a decimal point at the end. These numbers are used for measuring quantities. Examples of valid floating point numbers are: 27.4, -92.7, and 40.03. 

A float type data can be used to hold numbers from 3.4*10-38 to 3.4*10+38 with six or seven digits of precision. However, for more precision a double precision type (double) can be used to hold numbers from 1.7*10-308 to 1.7*10+308 with about 15 digits of precision. 

Void data type 

It is used for following purposes: 

It specifies the return type of a function when the function is not returning any value. 

It indicates an empty parameter list on a function when no arguments are passed. 

A void pointer can be assigned a pointer value of any basic data type. 

Char data type 

It is used to store character values in the identifier. Its size and range of values.

Basic Fundamental Data Type

Derived Data types 

C++ also permits four types of derived data types. As the name suggests, derived data types are basically derived from the built-in data types. There are four derived data types. 

These are: 

  • Array 
  • Function 
  • Pointer, and 
  • Reference

User Defined Data Types

C++ also permits four types of user defined data types. As the name suggests, user defined data types are defined by the programmers during the coding of software development. 

There are four user defined data types. These are: 

  • Structure 
  • Union 
  • Class, and 
  • Enumerator


"data types in C++ with examples"

"data types in C++"

"how many data types in C++"

"non primitive data types in C++"

"derived data types in C++"

"string data types in C++"

"data types in C++ language"

"data types in C++ definition"

"size of data types in C++"

"user defined data types in C++"

"derived data types in C++"

"basic data types in C++"

"primitive data types in C++"

"structure data types in C++"