[1] A data type specification in a program constrains the possible values that an expression, such as a variable or a function call, might take.
It is frequently a matter of good organization that aids the understanding of complex definitions.
An explicit data type declaration typically allows the compiler to choose an efficient machine representation, but the conceptual organization offered by data types should not be discounted.
For example, in the Python programming language, int represents an arbitrary-precision integer which has the traditional numeric operations such as addition, subtraction, and multiplication.
However, in the Java programming language, the type int represents the set of 32-bit integers ranging in value from −2,147,483,648 to 2,147,483,647, with arithmetic operations that wrap on overflow.
In Rust this 32-bit integer type is denoted i32 and panics on overflow in debug mode.
For example, a programmer might create a new data type named "complex number" that would include real and imaginary parts, or a color data type represented by three bytes denoting the amounts each of red, green, and blue, and a string representing the color's name.
In a type system, a data type represents a constraint placed upon the interpretation of data, describing representation, interpretation and structure of values or objects stored in computer memory.
Types including behavior align more closely with object-oriented models, whereas a structured programming model would tend to not include code, and are called plain old data structures.
Data types may be categorized according to several factors: The terminology varies - in the literature, primitive, built-in, basic, atomic, and fundamental may be used interchangeably.
[8] All data in computers based on digital electronics is represented as bits (alternatives 0 and 1) on the lowest level.
In higher-level languages most data types are abstracted in that they do not have a language-defined machine representation.
They may either supply a small number of predefined subtypes restricted to certain ranges (such as short and long and their corresponding unsigned variants in C/C++); or allow users to freely define subranges such as 1..12 (e.g. Pascal/Ada).
Floating point data types represent certain fractional values (rational numbers, mathematically).
Fixed point data types are convenient for representing monetary values.
For independence from architecture details, a Bignum or arbitrary precision numeric type might be supplied.
This represents an integer or rational to a precision limited only by the available memory and computational resources on the system.
[10] The enumerated type has distinct values, which can be compared and assigned, but which do not necessarily have any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.
If a variable V is declared having suit as its data type, one can assign any of those four values to it.
Characters may be a letter of some alphabet, a digit, a blank space, a punctuation mark, etc.
A union type definition will specify which of a number of permitted subtypes may be stored in its instances, e.g. "float or long integer".
In contrast with a record, which could be defined to contain a float and an integer, a union may only contain one subtype at a time.
If there is only one constructor, then the ADT corresponds to a product type similar to a tuple or record.
For example, a stack has push/pop operations that follow a Last-In-First-Out rule, and can be concretely implemented using either a list or an array.
Abstract data types are used in formal semantics and program verification and, less strictly, in design.
(In everyday terms, a page number in a book could be considered a piece of data that refers to another one).
For example, in Java the class Boolean implements both the Serializable and the Comparable interfaces.
[citation needed] For convenience, high-level languages and databases may supply ready-made "real world" data types, for instance times, dates, and monetary values (currency).