Datatype Website Links For
Data
 

Information About

Datatype




In , the "int" type represents the set of 32-bit integers ranging in value from -2,147,483,648 to 2,147,483,647, and the operations such as addition, subtraction, and multiplication that can be performed on integers. Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology. Common data types in programming languages include those that represent integers, floating point numbers, and characters, and a language may support many more. Most programming languages also allow the programmer to define additional data types, usually by combining multiple elements of other types and defining the valid operations of the new data type. For example, a programmer might create a new data type named "Person" that specifies that data interpreted as Person would include a name and a date of birth.

A data type can also be thought of as a constraint placed upon the interpretation of data in a Type System , describing representation, interpretation and structure of Value s or Object s stored in computer memory. The type system uses data type information to check Correctness of computer programs that access or manipulate the data.


MACHINE DATA TYPES

All data in computers based on digital electronics is represented as Bit s (alternatives 0 and 1) on the lowest level. The smallest addressable unit of data is a group of bits called a Byte (usually an Octet , which is 8 bits). The unit processed by Machine Code instructions is called a Word (as of 2006, typically 32 or 64 bits). Most instructions interpret the word as a Binary Number , such that a 32-bit word can represent unsigned integer values from 0 to 2^{32}-1 or signed integer values from -2^{31} to 2^{31}-1. Because of Two's Complement , the machine language and machine don't need to distinguish between these unsigned and signed data types for the most part.

There is a specific set of arithmetic instructions that use a different interpretation of the bits in word as a Floating-point number.


PRIMITIVE TYPES


Integer numbers

An integer number can hold a whole number, but no fraction. Integers may be either signed (allowing negative values) or unsigned (nonnegative values only). Typical sizes of integers are:

Literals for integers consist of a sequence of digits. Most programming languages disallow the use of commas for Digit Grouping , although
FORTRAN (77 and Fortran 90 and above fixed form source but not free form source) allows embedded spaces and D allows embedded Underscore s. Negation is indicated by a minus sign (-) before the value. Examples of integer literals are:

  • 42

  • 10000

  • -233000



Booleans


A Boolean type, typically denoted "bool" or "boolean", is a single-bit type that can be either "true" (1) or "false" (0). In some languages (e.g., C++ ), bools may be implicitly converted to integers (for example, "true + true" is a valid expression equal to 2), but other languages (e.g., Java and Pascal ) disallow this.


Floating-point numbers


A Floating-point number represents a Real Number that may have a fractional part. These numbers are stored internally in Scientific Notation , typically in Binary but sometimes in Decimal . Because floating-point number have only a limited number of digits, most values can be represented only approximately.

Many languages have both a Single Precision (often called "float") and a Double Precision type.

Literals for floating point numbers include a decimal point, and typically use "e" to denote scientific notation. Examples of floating-point literals are:

  • 20.0005

  • 99.9

  • -5000.12

  • 6.02e23


Some languages (e.g., FORTRAN ) also have a Complex Number type comprising two floating-point numbers: a real part and an imaginary part.


Characters and strings


A Character type (typically called "char") may contain a single Letter , Digit , Punctuation Mark , or Control Character . Some languages have two character types, a single-byte type for ASCII characters and a multi-byte type for Unicode characters.

Characters may be combined into Strings . The string data can include numbers and other numerical symbols but will be treated as text.

In most languages, a string is equivalent to an array of characters, but Java treats them as distinct types. Other languages (such as FORTRAN , Python , and many dialects of BASIC ) have no separate character type, but only strings with a length of one.

Literals for characters and strings are usually surrounded by Quotation Marks : often, single quotes (') are used for characters and double quotes (") are used for strings.

Examples of character literals in C syntax are:

Examples of string literals in C syntax are:
  • "A"

  • "Hello World"

  • "I am 6000 years old"



Numeric data type ranges

Each numeric data type has a maximum and minimum value known as the Range . Attempting to store a number outside the range may lead to compiler/runtime errors, or to incorrect calculations (due to Truncation ) depending on the language being used.

The range of a variable is based on the number of bytes used to save the value, and an integer data type is usuallyThere are situations where one or more bits are reserved for other functions, e.g. parity checking. able to store 2^n values (where n is the number of Bit s). For other data types (e.g. Floating Point values) the range is more complicated and will vary depending on the method used to store it. There are also some types that do not use entire bytes, e.g. a boolean that requires a single Bit , and represents a Binary value (although in practice a byte is often used, with the remaining 7 bits being redundant). Some programming languages (such as Ada and Pascal ) also allow the opposite direction, that is, the programmer defines the range and precision needed to solve a given problem and the compiler chooses the most appropriate integer or floating point type automatically.


COMPOSITE TYPES

See Also: Composite type




ABSTRACT DATA TYPES

See Also: Abstract data type




POINTER AND REFERENCE TYPES

See Also: Reference (computer science)




ALGEBRAIC TYPES

See Also: Algebraic data type




OBJECT TYPES

See Also: Object (computer science)




FUNCTION TYPES

See Also: Function type




SEE ALSO

  • Type Theory for the mathematical models of types

  • Type System for different choices in programming language typing



NOTES



REFERENCES

  • Luca Cardelli, Peter Wegner. ''On Understanding Types, Data Abstraction, and Polymorphism,'' {Link without Title} from Computing Surveys, (December, 1985)