What is a 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.
What is a data type in programming?
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.

Common data types
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:
- Integer (int). Whole numbers (numbers without fractions).
- Examples: 901, -43
- Floating point (float or real). Fractional or decimal numbers.
- Examples: 433.98, 1.23E2
- Character (char). Single letters, numbers or special characters (e.g., punctuation marks).
- Examples: A, !, &
- String (str). A sequence or combination of letters, numbers or special characters.
- Examples: InformaTechTarget, Hi there!
- Boolean (bool). True or false values that clarify a conditional statement.
- Example: bool InformaTechTargetisGreat = true
- Date. A calendar date in a specific format such as YYYY-MM-DD.
- Example: 2025-04-01
- Time. Time in a specific format such as hh:mm:ss.
- Example: 18:40:04
- Nothing or void. A code with no value.
- Array. A list with multiple elements of the same type and mentioned in a specific order; the length of an array refers to the total number of elements in it.
- Example: (0, 1, 2, 3, 4, 5)
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).

Data types in C
There are three main data types available in C programming:
- Primitive data types.
- Derived data types.
- User-defined data types (UDTs).
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.)
Data types in C++
Like C, C++ also supports multiple data types:
- Basic data types.
- Derived data types.
- UDTs.
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.
Data types in Java
Java has two main data types:
- Primitive.
- Non-primitive.
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.
Data types in Python
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'>
Static data and weakly typed data
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.
What is a user-defined data type?
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:
- C. C supports four UDTs. These are structure, enumeration (enum), union and typedef. Structures allow users to group items of different data types into a single type, while enum is useful to create custom data types with a set of named integer constants. Typedef is used to rename existing data types, and the union data type can contain elements of different data types, with all members of the union stored in the same memory location.
- C++. C++ supports 5 UDTs: class, structure, union, enumeration and typedef. A Class data type has its own data members and member functions. Users can access these functions in a class by creating an instance of that class. The other four data types in C++ are similar to those in C.
- Visual Basic for Applications (VBA). In VBA, users can define UDTs by using the type statement. These UDTs might contain a previously defined UDT, an array or multiple elements of a specific data type. The range of each data element is always the same as the range of its data type.
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.