Primitive data type
In computer science, primitive data types are the basic data types that all other data types are made from. They are the simplest kinds of information a computer can use. Usually, the term refers to the small set of data forms that a particular processor uses, and every compiled program must use these same forms.
Most processors have a similar set of primitive data types, although the exact ways they are stored can be different. The term can also mean the standard data types that come built into a programming language. These are called built-in types.
Data types that are not primitive are called derived or composite types. They are made by putting simpler types together.
Primitive types are almost always value types. Composite types can also be value types, though.
Common primitive data types
Main article: Integer (computer science)
Main article: Floating-point arithmetic
Main article: Boolean data type
The most common primitive types are the ones that computer hardware can use directly. These include whole numbers of different sizes, floating-point numbers, and true-or-false values. Working with these types is usually quite fast. For example, adding two whole numbers can be done with one machine instruction. Some processors also have special instructions that handle a row of characters with a single instruction. The type you choose can still change how fast a program runs. For example, it is faster to use SIMD operations and types on a group of floating-point numbers.
Integers are whole numbers within a range. They can be signed, which allows negative values, or unsigned, which allows non-negative integers only. Common ranges are:
A floating-point number is a rational number with limited precision, so it can have a fractional part. It is stored in a form similar to scientific notation, usually in binary but sometimes in decimal. Because of the limited precision, some real or rational numbers can be stored exactly, but others can only be stored approximately. Many languages have a single-precision type, often called float, and a double-precision type, often called double. A Boolean type, usually called bool or boolean, can be either true or false. Only one bit is needed for this, but languages usually store Booleans as one or more bytes. Languages such as Java, Pascal, and Ada treat Booleans as their own separate type. Some languages change Booleans into numbers at times. This gives Booleans and Boolean expressions extra semantics or keeps older programs working. Early versions of the C language, which followed ANSI C and its earlier standards, had no Boolean type. Instead, zero meant false and any other value meant true. The newer C99 added a Boolean type, and C++ supports bool as a built-in type.
| Size (bytes) | Size (bits) | Names | Signed range (two's complement representation) | Unsigned range |
|---|---|---|---|---|
| 1 byte | 8 bits | Byte, octet, minimum size of char in C99( see limits.h CHAR_BIT) | −128 to +127 | 0 to 255 |
| 2 bytes | 16 bits | x86 word, minimum size of short and int in C | −32,768 to +32,767 | 0 to 65,535 |
| 4 bytes | 32 bits | x86 double word, minimum size of long in C, actual size of int for most modern C compilers, pointer for IA-32-compatible processors | −2,147,483,648 to +2,147,483,647 | 0 to 4,294,967,295 |
| 8 bytes | 64 bits | x86 quadruple word, minimum size of long long in C, actual size of long for most modern C compilers, pointer for x86-64-compatible processors | −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |
Specific languages
Main article: C data types § Basic types
Each programming language has its own basic data types. In C and C++, there are at least four: char, int, float, and double. Words like short, long, signed, and unsigned change these types, so C has many versions that depend on the computer. C99 allowed long to be used twice with int. C23 made bool a core type. C++ has a std::byte type in its standard library, but it is an enum and not a basic type. C and C++ also have types like size_t for counting things, such as positions in lists. C++26 adds a mirror type for reflective programming (see Reflection (C++)).
Java's basic types are similar to C's. They include integer types like byte, short, int, long, and char. They also include floating-point numbers like float and double, and a Boolean type called boolean, which holds true or false. The Java virtual machine also has a returnAddress type, but programmers usually cannot use it.
The XML Schema Definition language has 19 basic types. They include string values made of Unicode code points, Calendar dates and times, binary data written as hexadecimal or Base64, URI addresses, and qualified names.
JavaScript has 7 basic types: string, number, bigint, boolean, symbol, undefined, and null. Their values cannot be changed once they are made (immutable). These basic types are not objects, so they have no methods or properties. Most of them do have object wrappers.
In Visual Basic (.NET), the basic types include whole-number types, decimal-number types, a decimal type, a Boolean type, a date and time type, a single character type, and a text string type.
Rust has signed and unsigned whole-number types such as u8, i32, and u128. It also has usize and isize, which are used for positions in arrays. It has bool for Boolean values, f32 and f64 for floating point numbers, and char for a single unicode character.
Built-in types
Built-in types are special types that are part of the compiler or runtime. They cannot simply be written in a header file or standard library. Besides integers, floating-point numbers, and Booleans, other built-in types include the void type and the nullptr_t null pointer type in C++11 and C23. Tuples are built in to Standard ML, Python, Scala, Swift, and Elixir. Lists are built in to Common Lisp, Python, Scheme, and Haskell.
Some languages also have fixed-point numbers. These have different precisions and a scale that the programmer chooses. Complex numbers are built in to C99, Fortran, Common Lisp, Python, D, and Go. A complex number has a real part and an imaginary part.
An enumerated type is a list of names for the values that are allowed. This can make code easier to read and check. Other examples include rational numbers and arbitrary-precision Integer types. These appear in Common Lisp, Erlang, and Haskell. Associative arrays, records, and sets are also built-in types in Perl, PHP, Python, Ruby, JavaScript, Lua, D, and Go. References are built in too. They are also called a pointer, a handle, or a descriptor. Lisp has symbols, and functional languages have first-class functions. So do JavaScript, Lua, D, Go, newer versions of C++, Java, C#, and Perl.
Characters and strings are also built-in types. A character type can represent all Unicode characters, so it must be at least 21 bits wide. Julia has a true 32-bit Unicode character type. Some languages, such as JavaScript, Python, Ruby, and many versions of BASIC, have no basic character type. Instead, they use strings as a basic data type. These strings often use the UTF-8 encoding. A string with one letter usually stands for a single character.
Some languages have character types that are too small for all Unicode characters. In these languages, the "character" type is really an integer type with a confusing name. For example, C's char is the smallest unit of memory that can be addressed. Standards such as POSIX require it to be 8 bits. Java's char is a 16-bit integer.
The word "string" does not always mean Unicode characters. It can also mean a sequence of bytes. For example, x86-64 string instructions work on items that are 1, 2, 4, or 8 bytes long.

Quiz time!
4 questions about Primitive data type
What are primitive data types?
Keep exploring
This article is a child-friendly adaptation of the Wikipedia article on Primitive data type, available under CC BY-SA 4.0.