# Primitive data type

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Primitive_data_type
> Markdown URL: https://mediated.wiki/source/Primitive_data_type.md
> Source: https://en.wikipedia.org/wiki/Primitive_data_type
> Source revision: 1338409336
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Extremely basic data type

In [computer science](/source/Computer_science), **primitive data types** are sets of basic [data types](/source/Data_type) from which all other data types are constructed.[1] Specifically it often refers to the limited set of data representations in use by a particular [processor](/source/Central_processing_unit), which all compiled programs must use. Most processors support a similar set of primitive data types, although the specific representations vary.[2] More generally, *primitive data types* may refer to the standard data types built into a [programming language](/source/Programming_language) (**built-in types**).[3][4] Data types which are not primitive are referred to as *derived* or [*composite*](/source/Composite_data_type).[3]

Primitive types are almost always [value types](/source/Value_type), but composite types may also be value types.[5]

## Common primitive data types

The most common primitive types are those used and supported by computer hardware, such as [integers](/source/Integer_(computer_science)) of various sizes, [floating-point](/source/Floating_point) numbers, and [Boolean](/source/Boolean_data_type) logical values. Operations on such types are usually quite efficient. Primitive data types which are native to the processor have a one-to-one correspondence with objects in the computer's memory, and operations on these types are often the fastest possible in most cases.[6] Integer addition, for example, can be performed as a single machine instruction, and some offer specific instructions to process sequences of characters with a [single instruction](/source/Single_instruction%2C_single_data).[7] But the choice of primitive data type may affect performance, for example it is faster using [SIMD](/source/SIMD) operations and data types to operate on an array of floats.[6]: 113

### Integer numbers

Main article: [Integer (computer science)](/source/Integer_(computer_science))

An [integer](/source/Integer_(computer_science)) data type represents some [range](/source/Range_(computer_programming)) of mathematical integers. Integers may be either signed (allowing negative values) or unsigned ([non-negative integers](/source/Non-negative_integer) only). Common ranges are:

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,[8] 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,[8] 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

### Floating-point numbers

Main article: [Floating-point arithmetic](/source/Floating-point_arithmetic)

A [floating-point](/source/Floating-point) number represents a limited-precision [rational number](/source/Rational_number) that may have a fractional part. These numbers are stored internally in a format equivalent to [scientific notation](/source/Scientific_notation), typically in [binary](/source/Binary_numeral_system) but sometimes in [decimal](/source/Decimal). Because floating-point numbers have limited precision, only a subset of [real](/source/Real_number) or [rational](/source/Rational_number) numbers are exactly representable; other numbers can be represented only approximately. Many languages have both a [single-precision](/source/Single-precision_floating-point_format) (often called *float*) and a [double-precision](/source/Double-precision_floating-point_format) type (often called *double*).

### Booleans

Main article: [Boolean data type](/source/Boolean_data_type)

A [Boolean type](/source/Boolean_type), typically denoted *bool* or *boolean*, is typically a *logical type* that can have either the value *true* or the value *false*. Although only one bit is necessary to accommodate the value set *true* and *false*, programming languages typically implement Boolean types as one or more bytes.

Many languages (e.g. [Java](/source/Java_(programming_language)), [Pascal](/source/Pascal_(programming_language)) and [Ada](/source/Ada_(programming_language))) implement Booleans adhering to the concept of Boolean as a distinct logical type. Some languages, though, may implicitly convert Booleans to *numeric types* at times to give extended semantics to Booleans and Boolean expressions or to achieve backwards compatibility with earlier versions of the language. For example, early versions of the C programming language that followed [ANSI C](/source/ANSI_C) and its former standards did not have a dedicated Boolean type. Instead, numeric values of zero are interpreted as *false*, and any other value is interpreted as *true*.[9] The newer [C99](/source/C99) added a distinct Boolean type _Bool (later moved to bool as well as the keywords true and false with [C23](/source/C23_(C_standard_revision))),[10] and [C++](/source/C%2B%2B) supports bool as a built-in type and *true* and *false* as reserved words.[11]

## Specific languages

### C and C++ basic types

Main article: [C data types § Basic types](/source/C_data_types#Basic_types)

In [C](/source/C_(programming_language)) and [C++](/source/C%2B%2B), there are minimally four types, char, int, float, and double, but the qualifiers short, long, signed, and unsigned mean that C contains numerous target-dependent integer and floating-point primitive types.[12] [C99](/source/C99) allowed the modifier long to be used twice in combination with int (e.g. long long int).[13] Similarly, signed and unsigned can be used as modifiers for integral types. [C23](/source/C23_(C_standard_revision)) introduced the bool type as a core data type, while it was always a core data type of C++. C++ also features a std::byte type (similar to Java).

C and C++ also contain size_t, intptr_t and other integer types, for things like indexing arrays and collections. These are not distinct data types, but often aliases and are system-defined. These are perhaps similar to Rust usize and isize.

### Java

The basic types of Java are similar to that of C. The [Java](/source/Java_(programming_language)) virtual machine's set of primitive data types consists of:[14]

- byte, short, int, long, char ([integer](/source/Integer_(computer_science)) types with a variety of ranges)

- float and double, [floating-point numbers](/source/Floating_point) with single and double [precisions](/source/Precision_(computer_science))

- boolean, a [Boolean](/source/Boolean_data_type) type with logical values true and false

- returnAddress, a value referring to an executable memory address. This is not accessible from the Java programming language and is usually left out.[15][16]

### XML Schema

The [XML Schema Definition](/source/XML_Schema_Definition) language provides a set of 19 primitive data types:[17]

- string: a [string](/source/String_(computer_science)), a sequence of [Unicode code points](/source/Unicode_code_point)

- boolean: a [Boolean](/source/Boolean_data_type)

- decimal: a number represented with [decimal](/source/Decimal) notation

- float and double: [floating-point](/source/Floating-point) numbers

- duration, dateTime, time, date, gYearMonth, gYear, gMonthDay, gDay, and gMonth: [Calendar dates](/source/Calendar_date) and times

- hexBinary and base64Binary: [binary data](/source/Binary_data) encoded as [hexadecimal](/source/Hexadecimal) or [Base64](/source/Base64)

- anyURI: a [URI](/source/URI)

- QName: a [qualified name](/source/QName)

- NOTATION: a QName declared as a notation in the schema. Notations are used to embed non-XML data types.[18] This type cannot be used directly - only derived types that enumerate a limited set of QNames may be used.

### JavaScript

In JavaScript, there are 7 primitive data types: string, number, bigint, boolean, symbol, undefined, and null.[19] Their values are considered [immutable](/source/Immutable). These are not objects and have no [methods](/source/Method_(computer_programming)) or [properties](/source/Property_(programming)); however, all primitives except undefined and null have [object wrappers](https://en.wikipedia.org/w/index.php?title=Object_wrapper&action=edit&redlink=1).[20]

### Visual Basic .NET

In [Visual Basic .NET](/source/Visual_Basic_.NET), the primitive data types consist of 4 integral types, 2 floating-point types, a 16-byte decimal type, a Boolean type, a date/time type, a Unicode character type, and a Unicode string type.[21]

### Rust

Rust has primitive unsigned and signed fixed width integers in the format u or i respectively followed by any bit width that is a power of two between 8 and 128 giving the types u8, u16, u32, u64, u128, i8, i16, i32, i64 and i128.[22] Also available are the types usize and isize which are unsigned and signed integers that are the same bit width as a reference with the usize type being used for indices into arrays and indexable collection types.[22]

Rust also has:

- bool for the [Boolean](/source/Boolean_data_type) type.[22]

- f32 and f64 for 32 and 64-bit [floating point numbers](/source/Floating-point_arithmetic).[22]

- char for a [unicode character](/source/Universal_Character_Set_characters). Under the hood these are unsigned 32-bit integers with values that correspond to the char's codepoint but only values that correspond to a valid unicode scalar value are valid.[22]

## Built-in types

Built-in types are distinguished from others by having specific support in the compiler or runtime, to the extent that it would not be possible to simply define them in a header file or standard library module.[23] Besides integers, floating-point numbers, and Booleans, other built-in types include:

- The [void type](/source/Void_type) and null pointer type [nullptr_t](/source/Nullptr_t) in [C++11](/source/C%2B%2B11) and [C23](/source/C23_(C_standard_revision))

- Characters and strings (see [below](#Characters_and_strings))

- [Tuple](/source/Tuple) in [Standard ML](/source/Standard_ML), [Python](/source/Python_(programming_language)), [Scala](/source/Scala_(programming_language)), [Swift](/source/Swift_(programming_language)), [Elixir](/source/Elixir_(programming_language))

- [List](/source/List_(abstract_data_type)) in [Common Lisp](/source/Common_Lisp), [Python](/source/Python_(programming_language)), [Scheme](/source/Scheme_(programming_language)), [Haskell](/source/Haskell_(programming_language))

- [Fixed-point number](/source/Fixed-point_arithmetic) with a variety of [precisions](/source/Precision_(computer_science)) and a programmer-selected [scale](/source/Order_of_magnitude).

- [Complex number](/source/Complex_data_type) in [C99](/source/C99), [Fortran](/source/Fortran), [Common Lisp](/source/Common_Lisp), [Python](/source/Python_(programming_language)), [D](/source/D_(programming_language)), [Go](/source/Go_(programming_language)). This is two floating-point numbers, a real part and an imaginary part.

- [Enumerated type](/source/Enumerated_type) sequence of names for allowed values; can improve readability and type checking.

- [Rational number](/source/Rational_data_type) in [Common Lisp](/source/Common_Lisp)

- [Arbitrary-precision](/source/Arbitrary-precision_arithmetic) Integer type in [Common Lisp](/source/Common_Lisp), [Erlang](/source/Erlang_(programming_language)), [Haskell](/source/Haskell_(programming_language))

- [Associative arrays](/source/Associative_array), [records](/source/Record_(computer_science)) or [sets](/source/Set_(abstract_data_type)) in [Perl](/source/Perl), [PHP](/source/PHP), [Python](/source/Python_(programming_language)), [Ruby](/source/Ruby_(programming_language)), [JavaScript](/source/JavaScript), [Lua](/source/Lua_(programming_language)), [D](/source/D_(programming_language)), [Go](/source/Go_(programming_language))

- [Reference](/source/Reference_(computer_science)) (also called a *[pointer](/source/Pointer_(computer_programming))* or *handle* or *descriptor*),

- [Symbols](/source/Symbol_(programming)), in [Lisp](/source/Lisp_(programming_language))

- [First-class function](/source/First-class_function), in all [functional](/source/Functional_programming) languages, [JavaScript](/source/JavaScript), [Lua](/source/Lua_(programming_language)), [D](/source/D_(programming_language)), [Go](/source/Go_(programming_language)), and in newer standards of [C++](/source/C%2B%2B), [Java](/source/Java_(programming_language)), [C#](/source/C_Sharp_(programming_language)), [Perl](/source/Perl)

### Characters and strings

A [character](/source/Character_(computing)) type is a type that can represent all [Unicode characters](/source/Unicode_characters), hence must be at least 21 bits wide. Some languages such as Julia include a true 32-bit Unicode character type as primitive.[24] Other languages such as [JavaScript](/source/JavaScript), [Python](/source/Python_(programming_language)), [Ruby](/source/Ruby_(programming_language)), and many dialects of [BASIC](/source/BASIC) do not have a primitive character type but instead add [strings](/source/String_(computer_science)) as a primitive data type, typically using the [UTF-8](/source/UTF-8) encoding. Strings with a length of one are normally used to represent single characters.

Some languages have *character* types that are too small to represent all Unicode characters. These are more properly categorized as integer types that have been given a misleading name. For example C includes a char type, but it is defined to be the smallest addressable unit of memory, which several standards (such as [POSIX](/source/POSIX)) require to be 8 [bits](/source/Bit). Recent versions of these standards refer to char as a numeric type. char is also used for a 16-bit integer type in [Java](/source/Java_(programming_language)), but again this is not a Unicode character type.[25]

The term *string* also does not always refer to a sequence of Unicode characters, instead referring to a sequence of bytes. For example, x86-64 has *string* instructions to move, set, search, or compare a sequence of items, where an item could be 1, 2, 4, or 8 bytes long.[26]

## See also

- [Language primitive](/source/Language_primitive) – Microcode in programming language

- [List of data structures § Data types](/source/List_of_data_structures#Data_types)

- [Object type](/source/Object_type) – Programming language conceptPages displaying short descriptions of redirect targets

- [Primitive wrapper class](/source/Primitive_wrapper_class)

- [Variable (high-level programming language)](/source/Variable_(high-level_programming_language)) – Named container for a particular type of data

## References

1. **[^](#cite_ref-1)** Stone, R. G.; Cooke, D. J. (5 February 1987). [*Program Construction*](https://books.google.com/books?id=0k_xz8O2SewC&pg=PA18). Cambridge University Press. p. 18. [ISBN](/source/ISBN_(identifier)) [978-0-521-31883-9](https://en.wikipedia.org/wiki/Special:BookSources/978-0-521-31883-9).

1. **[^](#cite_ref-2)** Wikander, Jan; Svensson, Bertil (31 May 1998). [*Real-Time Systems in Mechatronic Applications*](https://books.google.com/books?id=fDCNR7VwG-AC&pg=PA101). Springer Science & Business Media. p. 101. [ISBN](/source/ISBN_(identifier)) [978-0-7923-8159-4](https://en.wikipedia.org/wiki/Special:BookSources/978-0-7923-8159-4).

1. ^ [***a***](#cite_ref-Khurana_3-0) [***b***](#cite_ref-Khurana_3-1) Khurana, Rohit. [*Data and File Structure (For GTU), 2nd Edition*](https://books.google.com/books?id=s0JDDAAAQBAJ&pg=PA2). Vikas Publishing House. p. 2. [ISBN](/source/ISBN_(identifier)) [978-93-259-6005-3](https://en.wikipedia.org/wiki/Special:BookSources/978-93-259-6005-3).

1. **[^](#cite_ref-4)** Chun, Wesley (2001). [*Core Python Programming*](https://books.google.com/books?id=mh0bU6NXrBgC&pg=PA77). Prentice Hall Professional. p. 77. [ISBN](/source/ISBN_(identifier)) [978-0-13-026036-9](https://en.wikipedia.org/wiki/Special:BookSources/978-0-13-026036-9).

1. **[^](#cite_ref-5)** Olsen, Geir; Allison, Damon; Speer, James (1 January 2008). [*Visual Basic .NET Class Design Handbook: Coding Effective Classes*](https://books.google.com/books?id=DUQnCgAAQBAJ&pg=PA80). Apress. p. 80. [ISBN](/source/ISBN_(identifier)) [978-1-4302-0780-1](https://en.wikipedia.org/wiki/Special:BookSources/978-1-4302-0780-1).

1. ^ [***a***](#cite_ref-Agner_6-0) [***b***](#cite_ref-Agner_6-1) Fog, Agner. ["Optimizing software in C++"](https://www.agner.org/optimize/optimizing_cpp.pdf#page=29) (PDF). p. 29. Retrieved 28 January 2022. Integer operations are fast in most cases, [...]

1. **[^](#cite_ref-7)** Hennessy, John L.; Patterson, David A. (August 2011). [*Computer Architecture, Fifth Edition: A Quantitative Approach*](https://dl.acm.org/doi/10.5555/1999263) (5th ed.). San Francisco, CA, USA: Morgan Kaufmann Publishers Inc. [ISBN](/source/ISBN_(identifier)) [978-0-12-383872-8](https://en.wikipedia.org/wiki/Special:BookSources/978-0-12-383872-8).

1. ^ [***a***](#cite_ref-agnerfog_8-0) [***b***](#cite_ref-agnerfog_8-1) Fog, Agner (2010-02-16). ["Calling conventions for different C++ compilers and operating systems: Chapter 3, Data Representation"](http://www.agner.org/optimize/calling_conventions.pdf) (PDF). Retrieved 2010-08-30.

1. **[^](#cite_ref-9)** [Kernighan, Brian W](/source/Brian_Kernighan); [Ritchie, Dennis M](/source/Dennis_Ritchie) (1978). *[The C Programming Language](/source/The_C_Programming_Language)* (1st ed.). [Englewood Cliffs, NJ](/source/Englewood_Cliffs%2C_NJ): [Prentice Hall](/source/Prentice_Hall). p. [41](https://archive.org/details/cprogramminglang00kern/page/41). [ISBN](/source/ISBN_(identifier)) [0-13-110163-3](https://en.wikipedia.org/wiki/Special:BookSources/0-13-110163-3).

1. **[^](#cite_ref-10)** ["Boolean type support library"](https://devdocs.io/c/types/boolean). *devdocs.io*. Retrieved October 15, 2020.

1. **[^](#cite_ref-11)** ["Bool data type in C++"](https://www.geeksforgeeks.org/bool-data-type-in-c/). *GeeksforGeeks*. 5 June 2017. Retrieved October 15, 2020.

1. **[^](#cite_ref-12)** Kernighan, Brian W.; Ritchie, Dennis M. (1988). "2.2 Data Types and Sizes". *The C programming language* (Second ed.). Englewood Cliffs, N.J. p. 36. [ISBN](/source/ISBN_(identifier)) [0131103709](https://en.wikipedia.org/wiki/Special:BookSources/0131103709).{{[cite book](https://en.wikipedia.org/wiki/Template:Cite_book)}}: CS1 maint: location missing publisher ([link](https://en.wikipedia.org/wiki/Category:CS1_maint:_location_missing_publisher))

1. **[^](#cite_ref-c99newtypes_13-0)** [*ISO/IEC 9899:1999 specification, TC3*](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) (PDF). p. 255, § 6.2.5 *Types*.

1. **[^](#cite_ref-14)** Lindholm, Tim; Yellin, Frank; Bracha, Gilad; Buckley, Alex (13 February 2015). "Chapter 2. The Structure of the Java Virtual Machine". [*The Java® Virtual Machine Specification*](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.3).

1. **[^](#cite_ref-15)** Cowell, John (18 February 1997). [*Essential Java Fast: How to write object oriented software for the Internet*](https://books.google.com/books?id=5M9_fBX4QicC&pg=PA27). Springer Science & Business Media. p. 27. [ISBN](/source/ISBN_(identifier)) [978-3-540-76052-8](https://en.wikipedia.org/wiki/Special:BookSources/978-3-540-76052-8).

1. **[^](#cite_ref-16)** Rakshit, Sandip; Panigrahi, Goutam (December 1995). [*A Hand Book of Objected Oriented Programming With Java*](https://books.google.com/books?id=aAsbEAAAQBAJ&pg=PA11). S. Chand Publishing. p. 11. [ISBN](/source/ISBN_(identifier)) [978-81-219-3001-7](https://en.wikipedia.org/wiki/Special:BookSources/978-81-219-3001-7).

1. **[^](#cite_ref-17)** Biron, Paul V.; Malhotra, Ashok. ["XML Schema Part 2: Datatypes"](https://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes). *www.w3.org* (Second ed.). Retrieved 29 January 2022.

1. **[^](#cite_ref-18)** Phillips, Lee Anne (18 January 2002). ["Declaring a NOTATION | Understanding XML Document Type Definitions"](https://www.informit.com/articles/article.aspx?p=24992&seqNum=5). *www.informit.com*. Retrieved 29 January 2022.

1. **[^](#cite_ref-19)** ["Primitive - MDN Web Docs Glossary: Definitions of Web-related terms"](https://developer.mozilla.org/en-US/docs/Glossary/Primitive). MDN. 8 June 2023.

1. **[^](#cite_ref-20)** ["JavaScript data types and data structures"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values). MDN. 9 July 2024.

1. **[^](#cite_ref-21)** ["Types in Visual Basic"](https://docs.microsoft.com/en-us/dotnet/visual-basic/reference/language-specification/types#primitive-types). *Microsoft Docs*. 18 September 2021. Retrieved 18 May 2022.

1. ^ [***a***](#cite_ref-:0_22-0) [***b***](#cite_ref-:0_22-1) [***c***](#cite_ref-:0_22-2) [***d***](#cite_ref-:0_22-3) [***e***](#cite_ref-:0_22-4) ["Data Types - The Rust Programming Language"](https://doc.rust-lang.org/book/ch03-02-data-types.html). *doc.rust-lang.org*. Retrieved 2023-10-17.

1. **[^](#cite_ref-23)** ["Built-in types (C++)"](https://learn.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=msvc-170). *learn.microsoft.com*. 17 August 2021.

1. **[^](#cite_ref-24)** ["Strings · The Julia Language"](https://docs.julialang.org/en/v1/manual/strings/#man-characters). *docs.julialang.org*. Retrieved 29 January 2022.

1. **[^](#cite_ref-25)** Mansoor, Umer (8 May 2016). ["The char Type in Java is Broken"](https://codeahoy.com/2016/05/08/the-char-type-in-java-is-broken/). *CodeAhoy*. Retrieved 10 February 2020.

1. **[^](#cite_ref-26)** ["I/O and string instructions"](https://linasm.sourceforge.net/docs/instructions/cpu.php#bit). Retrieved 29 January 2022.

## External links

- Media related to [Primitive types](https://commons.wikimedia.org/wiki/Category:Primitive_types) at Wikimedia Commons

- [Differences Between Primitive Types and Objects](https://mta.ca/~rrosebru/oldcourse/comp1711/171102/comp1711A/numbers.html)

v t e Data types Uninterpreted Bit Byte Trit Tryte Word Bit array Numeric Arbitrary-precision or bignum Complex Decimal Fixed point Block floating point Floating point Reduced precision Minifloat Half precision bfloat16 Single precision Double precision Quadruple precision Octuple precision Extended precision Long double Integer signedness Interval Rational Reference Address physical virtual Pointer Text Character String null-terminated Composite Algebraic data type generalized Array Associative array Class Dependent Equality Inductive Intersection List Object metaobject Option type Product Record or Struct Refinement Set Union tagged Other Any type Boolean Bottom type Collection Enumerated type Exception Function type Opaque data type Recursive data type Semaphore Stream Strongly typed identifier Type class Empty type Unit type Void Related topics Value Abstract data type Boxing Data structure Generic Kind metaclass Parametric polymorphism Primitive data type Interface Subtyping Type constructor Type conversion Type system Type theory Variable

---
Adapted from the Wikipedia article [Primitive data type](https://en.wikipedia.org/wiki/Primitive_data_type) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Primitive_data_type?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
