DATA TYPE
(Redirected from Datatype)
In programming languages a 'data type' defines a set of values and the allowable operations on those values[1]. For example, in the Java programming language, 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 values or objects stored in computer memory. The type system uses data type information to check correctness of computer programs that access or manipulate the data.
All data in computers based on digital electronics is represented as bits (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 or signed integer values from to . 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.
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 underscores. Negation is indicated by a minus sign (-) before the value. Examples of integer literals are:
★ 42
★ 10000
★ -233000
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.
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.
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:
★ 'A'
★ '4'
★ '$'
★ ' ' (tab character)
Examples of string literals in C syntax are:
★ "A"
★ "Hello World"
★ "I am 6000 years old"
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 usually[2] able to store values (where is the number of bits). 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.
Main articles: Composite type
Main articles: Abstract data type
Main articles: Reference (computer science)
Main articles: Algebraic data type
Main articles: Object (computer science)
Main articles: Function type
★ Type theory for the mathematical models of types
★ Type system for different choices in programming language typing
1. http://www.sigcse.org/cc2001/PL.html
2. There are situations where one or more bits are reserved for other functions, e.g. parity checking.
★ Luca Cardelli, Peter Wegner. ''On Understanding Types, Data Abstraction, and Polymorphism,'' [1] from Computing Surveys, (December, 1985)
In programming languages a 'data type' defines a set of values and the allowable operations on those values[1]. For example, in the Java programming language, 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 values or objects 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 bits (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 or signed integer values from to . 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:
| Size | Names | Signed Range | Unsigned Range |
|---|---|---|---|
| 8 bits | Byte | -128 to +127 | 0 to 255 |
| 16 bits | Word, short int | -32,768 to +32,767 | 0 to 65 535 |
| 32 bits | Double Word, long int | -2,147,483,648 to +2,147,483,647 | 0 to 4,294,967,295 |
| 64 bits | long long (C), long (Java) | –9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |
| unlimited | Bignum |
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 underscores. 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:
★ 'A'
★ '4'
★ '$'
★ ' ' (tab character)
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 usually[2] able to store values (where is the number of bits). 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
Main articles: Composite type
Abstract data types
Main articles: Abstract data type
Pointer and reference types
Main articles: Reference (computer science)
Algebraic types
Main articles: Algebraic data type
Object types
Main articles: Object (computer science)
Function types
Main articles: Function type
See also
★ Type theory for the mathematical models of types
★ Type system for different choices in programming language typing
Notes
1. http://www.sigcse.org/cc2001/PL.html
2. There are situations where one or more bits are reserved for other functions, e.g. parity checking.
References
★ Luca Cardelli, Peter Wegner. ''On Understanding Types, Data Abstraction, and Polymorphism,'' [1] from Computing Surveys, (December, 1985)
This article provided by Wikipedia. To edit the contents of this article, click here for original source.
psst.. try this: add to faves

العربية
中国
Français
Deutsch
Ελληνική
हिन्दी
Italiano
日本語
Português
Русский
Español