Primitive types
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, primitive data types are a set of basic
data type In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed operations on it. A data type tells the compiler or Interpreter (computing), interpreter how the programmer intends to u ...
s from which all other data types are constructed. Specifically it often refers to the limited set of data representations in use by a particular processor, which all compiled programs must use. Most processors support a similar set of primitive data types, although the specific representations vary. More generally, "primitive data types" may refer to the standard data types built into a
programming language A programming language is a system of notation for writing computer program, computer programs. Most programming languages are text-based formal languages, but they may also be visual programming language, graphical. They are a kind of computer ...
. Data types which are not primitive are referred to as ''derived'' or ''composite''. Primitive types are almost always
value type In computer programming, data types can be divided into two categories: value types (or by-value types) and reference types (or by-reference types). Value types are completely represented by their meaning, while reference types are Reference (comput ...
s, but composite types may also be value types.


Common primitive data types

The
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
virtual machine's set of primitive data types is: *
Integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language of ...
types with a variety of ranges and precisions (byte, short, int, long, char) * Floating-point number with single or double precisions; (float, double) * Boolean, logical values true and false. (boolean) * A value referring to an executable memory address. (returnAddress) This is not accessible from the Java programming language and is usually left out. These primitive types are in general precisely those supported by computer hardware, except possibly for varying integer sizes or hardware that is missing floating point. Operations on such primitives 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. 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. But the choice of primitive data type may affect performance, for example it is faster using
SIMD Single instruction, multiple data (SIMD) is a type of parallel computer, parallel processing in Flynn's taxonomy. SIMD can be internal (part of the hardware design) and it can be directly accessible through an instruction set architecture (IS ...
operations and data types to operate on an array of floats. The set of basic
C data types In the C programming language ''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and im ...
is similar to Java's. Minimally, there are 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.


Integer numbers

An
integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language of ...
data type represents some range of mathematical integers. Integers may be either signed (allowing negative values) or unsigned (
non-negative integer In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country"). Numbers used for counting are called ''Cardinal n ...
s only). Common ranges are:


Floating-point numbers

A
floating-point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an Integer (computer science), integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. ...
number represents a limited-precision
rational number In mathematics, a rational number is a number that can be expressed as the quotient or fraction (mathematics), fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (e.g. ) ...
that may have a fractional part. These numbers are stored internally in a format equivalent to
scientific notation Scientific notation is a way of expressing real numbers, numbers that are too large or too small (usually would result in a long string of digits) to be conveniently written in decimal form. It may be referred to as scientific form or standard ...
, typically in binary but sometimes in
decimal The decimal numeral system (also called the base-ten positional numeral system and denary or decanary) is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral ...
. Because floating-point numbers have limited precision, only a subset of real or
rational Rationality is the Quality (philosophy), quality of being guided by or based on reasons. In this regard, a person Action (philosophy), acts rationally if they have a good reason for what they do or a belief is rational if it is based on strong e ...
numbers are exactly representable; other numbers can be represented only approximately. Many languages have both a
single precision Single-precision floating-point format (sometimes called FP32 or float32) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating point, floating radix poin ...
(often called "float") and a
double precision Double-precision floating-point format (sometimes called FP64 or float64) is a floating-point arithmetic, floating-point computer number format, number format, usually occupying 64 Bit, bits in computer memory; it represents a wide dynamic range o ...
type (often called "double").


Booleans

A 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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, Pascal and Ada) 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 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". The newer C99 added a distinct boolean type that can be included with stdbool.h, and C++ supports bool as a built-in type and "true" and "false" as reserved words.


XML Schema

The XML Schema Definition language provides a set of 19 primitive data types: * string: a
string String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * Strings (1991 film), ''Strings'' (1991 fi ...
, a sequence of Unicode code points * boolean: a boolean * decimal: a number represented with
decimal The decimal numeral system (also called the base-ten positional numeral system and denary or decanary) is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral ...
notation * float and double:
floating-point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an Integer (computer science), integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. ...
numbers * duration, dateTime, time, date, gYearMonth, gYear, gMonthDay, gDay, and gMonth:
Calendar date A calendar date is a reference to a particular day represented within a calendar system. The calendar date allows the specific day to be identified. The number of days between two dates may be calculated. For example, "25 " is ten days after "1 ...
s and times * hexBinary and base64Binary:
binary data Binary data is data whose unit can take on only two possible states. These are often labelled as 0 and 1 in accordance with the binary numeral system and Boolean algebra. Binary data occurs in many different technical and scientific fields, wher ...
encoded as
hexadecimal In mathematics and computing, the hexadecimal (also base-16 or simply hex) numeral system is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of 16. Unlike the decimal system ...
or
Base64 In computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming in ...
* anyURI: a URI * QName: a qualified name * NOTATION: a QName declared as a notation in the schema. Notations are used to embed non-XML data types. This type cannot be used directly - only derived types that enumerate a limited set of QNames may be used.


Built-in types

In JavaScript, there are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null. These are not objects and have no methods. In 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. In general, data types that can be built into sophisticated programming languages include: * Characters and strings (see below) * Ranges (see below) *
Tuple In mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in m ...
in
Standard ML Standard ML (SML) is a General-purpose programming language, general-purpose, Modular programming, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming l ...
,
Python Python may refer to: Snakes * Pythonidae The Pythonidae, commonly known as pythons, are a Family (biology), family of Venomous snake, nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes i ...
, Scala,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, a ...
,
Elixir ELIXIR (the European life-sciences Infrastructure for biological Information) is an initiative that will allow life science laboratories across Europe to share and store their research data as part of an organised network. Its goal is to bring t ...
*
List A ''list'' is any set of items in a row. List or lists may also refer to: People * List (surname) Organizations * List College, an undergraduate division of the Jewish Theological Seminary of America * SC Germania List, German rugby uni ...
in
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived ...
,
Python Python may refer to: Snakes * Pythonidae The Pythonidae, commonly known as pythons, are a Family (biology), family of Venomous snake, nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes i ...
, Scheme,
Haskell Haskell () is a General-purpose programming language, general-purpose, static typing, statically-typed, purely functional programming, purely functional programming language with type inference and lazy evaluation. Designed for teaching, resear ...
* Fixed-point number with a variety of precisions and a programmer-selected scale. *
Complex number In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form a ...
in C99, Fortran,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived ...
,
Python Python may refer to: Snakes * Pythonidae The Pythonidae, commonly known as pythons, are a Family (biology), family of Venomous snake, nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes i ...
, D, Go. This is two floating-point numbers, a real part and an imaginary part. *
Rational number In mathematics, a rational number is a number that can be expressed as the quotient or fraction (mathematics), fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (e.g. ) ...
in
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived ...
* Arbitrary-precision Integer type in
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived ...
, Erlang,
Haskell Haskell () is a General-purpose programming language, general-purpose, static typing, statically-typed, purely functional programming, purely functional programming language with type inference and lazy evaluation. Designed for teaching, resear ...
*
Associative array In computer science, an associative array, map, symbol table, or dictionary is an abstract data type that stores a collection (abstract data type), collection of attribute–value pair, (key, value) pairs, such that each possible key appears at ...
in
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offi ...
,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Gr ...
,
Python Python may refer to: Snakes * Pythonidae The Pythonidae, commonly known as pythons, are a Family (biology), family of Venomous snake, nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes i ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum (aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapp ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web The World Wide Web (WWW), commonly known as the Web, is an information system enabling documents and oth ...
, Lua, D, Go *
Reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name'' ...
(also called a '' pointer'' or ''handle'' or ''descriptor''), * First-class function, in all functional languages,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web The World Wide Web (WWW), commonly known as the Web, is an information system enabling documents and oth ...
, Lua, D, Go, and in newer standards of C++,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, C#,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offi ...


Characters and strings

A character type is a type that can represent all 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. Other languages such as
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web The World Wide Web (WWW), commonly known as the Web, is an information system enabling documents and oth ...
,
Python Python may refer to: Snakes * Pythonidae The Pythonidae, commonly known as pythons, are a Family (biology), family of Venomous snake, nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes i ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum (aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapp ...
, and many dialects of
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of General-purpose programming language, general-purpose, high-level programming languages designed for ease of use. Dartmouth BASIC, The original version was created by John ...
do not have a primitive character type but instead add strings as a primitive data type, typically using the
UTF-8 UTF-8 is a variable-length character encoding Character encoding is the process of assigning numbers to Graphics, graphical character (computing), characters, especially the written characters of Language, human language, allowing them to be ...
encoding. Strings with a length of one are normally used to represent single characters. Some languages have "character" or "string" types that are too small to represent all Unicode characters or strings. These are more properly categorized as integer types. 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 The Portable Operating System Interface (POSIX) is a family of standardization, standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application p ...
require to be 8 bits. The recent version of these standards refer to char as a numeric type. char is also used for a 16-bit integer type in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, but again this is not a Unicode character type. Some computer hardware has a few instructions which deal with "strings", referring to a sequence of bytes. For example, x86-64 can move, set, search, or compare a sequence of items, where an item could be 1, 2, 4, or 8 bytes long.


Ranges

A range numeric data type has its maximum and minimum value embedded in the type. It is included in some languages such as Ada and Pascal. Attempting to store a number outside the range may lead to compiler/runtime errors, or to incorrect calculations (due to
truncation In mathematics and computer science, truncation is limiting the number of numerical digit, digits right of the decimal point. Truncation and floor function Truncation of positive real numbers can be done using the floor function. Given a numb ...
) depending on the language being used. In practice the compiler chooses the most appropriate primitive integer or floating-point type automatically.


See also

* Language primitive * * Object type * Primitive wrapper class *
Variable (computer science) In computer programming, a variable is an abstract storage location paired with an associated symbol, symbolic name, which contains some known or unknown quantity of information referred to as a ''value (computer science), value''; or in simpler ...


References


External links

* {{DEFAULTSORT:Primitive data type Data types