https://www.techtarget.com/searchapparchitecture/definition/data-type
In software programming, a data type refers to the type of value a variable has and what type of mathematical, relational or logical operations can be applied on it without causing an error. For example, many programming languages use the data type string to classify text, integer to identify whole numbers and floating point to designate numbers with decimal points.
In any programming language, the data type defines which operations can safely be performed to create, transform and use the variable in another computation. Specifically, every piece of data has a type that tells the machine how to interpret its value.
Thus, if a data type is a string, the computer might interpret it as the name of a person or city, a greeting and so on. However, if the data is of type Boolean, the computer will know that it can only have one of two values: true or false. Similarly, the computer will interpret whole numbers and decimal numbers differently because they are of different data types: integer and float, respectively.
Different programming languages support different data types. These types enable the programs written in those languages to perform operations with, manipulate and use different types of data to produce appropriate, error-free output.
While the actual names of the data types might differ from one language to another, these data types are common to all languages:
In addition to the above data types, some languages also support data types like datetime (date and time together in a specific format), enumerated (a set of predefined values), long (a long positive or negative sequence of integers) and short (a short positive or negative sequence of integers).
There are three main data types available in C programming:
Primitive or built-in data types are used to represent simple data values, including characters, integers, void, float and double data.
Derived data types are derived from the primitive data types. They include arrays, pointers and functions. All three are important because they help programmers to build more efficient C programs.
UDTs in C include structure, union and enum. (These are described in greater detail in the section on UDTs.)
Like C, C++ also supports multiple data types:
As with C, the basic data types in C++ store simple values. These include int, float, double, char and void. C++ also includes a bool data type.
The derived data types in C++ include arrays, pointers, references and functions. All four types are used frequently to provide additional functionality to the basic data types and to build more complex programs.
In C++, one data type can be converted to another data type. This is known as type conversion and it makes it possible to handle different data types, without losing the meaning of the original data. Also, programmers can use keywords, known as data type modifiers, to change some aspect of an already existing data type, such as its size or range of data.
Java has two main data types:
There are eight primitive data types: byte, short, int, long, float, double, char and bool. Byte, short, int and long all store whole numbers, although with different ranges. Float and double store fractions; char stores a single character; and bool stores true or false values. A value of one primitive data type can be assigned to another type by using type casting. Type casting can be done automatically to convert a smaller type to a larger type size (e.g., byte to short), or manually to convert a larger type to a smaller size type (e.g., double to float).
There are three non-primitive data types: strings, arrays and classes, and they all refer to objects. For this reason, they are also known as reference types. Arrays and classes are created by users; strings are predefined in the language. Unlike primitive data types, programmers can use non-primitive data types to call methods to perform specific operations. They can also define non-primitive data types with "null" value. This is not possible with primitive data types.
Python is another high-level language that supports multiple data types. Eight data types that are built in by default include text, numeric, sequence, mapping, set, Boolean, binary and none.
To set a data type, a programmer simply assigns a value to a variable:
x = ""Informa TechTarget rocks" will assign the data type "str" to "Informa TechTarget rocks""
y = 30 will assign the data type "int" to the value "30""
z = {"New York", "Los Angeles", "Dallas"} will assign the data type "set" to "New York, Los Angeles, Dallas" " ""
Programmers can also use constructor functions to specify the data type. Here's what the above examples will look like with the appropriate constructor functions:
x = str("Informa TechTarget rocks")
y = int(30)
z = set(("New York", "Los Angeles", "Dallas"))
Python also provides a function called "type" to get the data type of any object.
So, if
x = 83
print(type(x))
Output:
<class 'int'>
In most programming languages, variable values commonly possess a static type. However, the values of those static types can still exist within multiple variable classes. While some classes specify how the data type's value will be compiled or interpreted, there are other classes whose values are not marked with their class until runtime.
The extent to which a programming language discourages or prevents type error is known as type safety. When a programming language requires a variable to be used only in ways that respect its data type, that language is said to be strongly typed. If data types do not align -- such as trying to multiply an integer by a string -- a strongly typed language will likely prevent the program from running to avert potential operational errors.
Programming languages that allow a variable of one data type to be used as if it were a value of another data type are said to be weakly typed. While the program might be allowed to run, the data mismatches could cause errors or crashes.
A user-defined data type (UDT) is a data type that a user can define and derive from an existing data type. Many UDTs have the same internal representation as built-in or source data types. These distinct UDTs increase the number of data types available to support a user's specific requirements.
Distinct UDTs can be either strongly typed or weakly typed. For strongly typed UDTs, functions and operators must be explicitly defined because they will not automatically acquire the functions and operators of the source data type. In contrast, weakly typed UDTs operate in the same way as the underlying source data type. That said, users can define certain constraints on the values of weak UDTs if required.
UDTs can also be structured instead of distinct. As the name suggests, structured UDTs have a specific structure that is predefined in the database. Each of these UDTs contains a sequence of named attributes as well as a set of method specifications. In addition to distinct and structured data types, users can also define array data types or row data types. An array might contain elements of another data type and a row data type is an ordered sequence of named fields.
Many programming languages support UDTs, including the following:
In addition to languages, UDTs can also be defined in some database management systems (DBMSes). For example, in Oracle's object-relational database management system (ORDBMS), users can define two types of UDTs: object types and collection types. An object type UDT is a templatized abstraction of some real-world entity and a collection data type is a data unit consisting of an indefinite number of elements of the same data type. Different schema objects can reference these UDTs in ORDBMSes. By defining UDTs, users can work with more types of more complex data to meet application requirements.
Learn about in-demand programming languages developers should get to know. Also, C has rapidly evolved since its inception. Examine the history of C, how it has evolved and why it's still relevant today. Explore benefits of Java and the top Java programming tools used in application development.
16 Apr 2025