Data type

In computer science, a data type is the combination of a value range[1] with permissible operations. Datatype is frequently shortened to type.

Programming

Data types in programming allow the programmer to perform operations on a datum. Every datum has an associated data type.

In the Pascal programming language, the data <syntaxhighlight lang="pascal" inline>42</syntaxhighlight> has the data type <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight>.

  • The data type <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> has a certain range of allowed values. For example, on an 8-bit computer, this range includes all whole numbers between <syntaxhighlight lang="pascal" inline>-127</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>127</syntaxhighlight>. The value <syntaxhighlight lang="pascal" inline>1337</syntaxhighlight>, however, is not an allowed <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> value.
  • Furthermore, the data type <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> allows certain operations: The operation <syntaxhighlight lang="pascal" inline>+</syntaxhighlight> can take two <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> dates and calculates their combined sum. There are many more operations. All those operations characterize the data type <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight>.

A data type forms a unit: Together, the specific permissible range and legal operations are referred to as a “concrete data type.” When a programmer or the compiler reads the word <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> in the source code, they automatically understand which values and operations are allowed.

Availability

High-level

Data types are an abstract concept. This concept primarily appears in high-level programming languages. Virtually all high-level programming language explicitly include the notion of data type. Common basic data types may include:[2]

Usually, these and other basic data types can be combined to custom data types using structure concepts like:

Low-level

The notion of data types as presented above is unknown in assembly language, a low-level programming language. All computers know integer number values. Modern computers also know real numbers in binary. But there is no rigid enforcement of proper “data type” use. Assembly language does not prevent using an integer as if it were a real number. This is intentional, because assembly language is the basis of all (high-level) programming languages.

Yet, the processor’s machine code sets the limits. Usually, the only “data types” are:

  • register names
  • memory addresses
  • immediate values

All of which may be further differentiated by their size, how many Bytes each of those occupies, or—in the case of memory address—how many Bytes the referenced object occupies.

Data Type Media

Related pages

  • File format: describes how to read or write a computer file (legal operations) and what this file may contain (permissible value range)
  • variable: variables in computer programming frequently require a data type

Sources

  1. "What is a Data Type?". www.computerhope.com. Retrieved 2019-05-23.
  2. "Data types and Type Systems - easily explained! | Data Basecamp". 2022-03-02. Retrieved 2022-06-11.