Value type and reference type
In computer programming, data types can be divided into two categories: value types and reference types. A value of value type is the actual value. A value of reference type is a reference to another value.
Classification per language
|Language||Value type||Reference type|
|C++||booleans, characters, integer numbers, floating-point numbers, classes (including strings, lists, maps, sets, stacks, queues), enumerations||references, pointers|
|Java||booleans, characters, integer numbers, floating-point numbers||arrays, classes (including immutable strings, lists, dictionaries, sets, stacks, queues, enumerations), interfaces, null pointer|
|C#||structures (including booleans, characters, integer numbers, floating-point numbers, fixed-point numbers, lists, dictionaries, sets, stacks, queues, optionals), enumerations||classes (including immutable strings, arrays, tuples, lists, dictionaries, sets, stacks, queues), interfaces, pointers|
|Swift||structures (including booleans, characters, integer numbers, floating-point numbers, fixed-point numbers, immutable strings, tuples, lists, dictionaries, sets, stacks, queues), enumerations (including optionals)||functions, classes, interfaces|
|Python||classes (including immutable booleans, immutable integer numbers, immutable floating-point numbers, immutable complex numbers, immutable strings, byte strings, immutable byte strings, immutable tuples, immutable ranges, immutable memory views, lists, dictionaries, sets, immutable sets, null pointer)|
|OCaml||immutable characters, immutable integer numbers, immutable floating-point numbers, immutable tuples, immutable enumerations (including immutable units, immutable booleans, immutable lists, immutable optionals), immutable exceptions, immutable formatting strings||arrays, immutable strings, byte strings, dictionaries (including pointers)|
Boxing and unboxing
Programming languages that distinguish between value types and reference types typically offer a mechanism, called boxing, to wrap some or all of their value types in reference types. This permits the use of value types in contexts expecting reference types. The converse process (to unwrap the value type) is known as unboxing.
- Brown, Erik E. (2006). Windows Forms in Action. Shelter Island, New York: Manning. p. 703. ISBN 978-1-932-39465-8.
- Stephens, Rod (2014). C# 5.0 Programmer's Reference. Indianapolis, Indiana: John Wiley & Sons. p. 57. ISBN 978-1-118-84728-2.