操作方式、含义、存储方式。

In computer science and computer programming, a data type or simply type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data, for example: realinteger or Boolean. A data type provides a set of values from which an expression (i.e. variable, function...) may take its values. The type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored.a type of value from which an expression may take its value.[1][2]

Data types are used within type systems, which offer various ways of defining, implementing and using them. Different type systems ensure varying degrees of type safety.

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 "complex number" that would include real and imaginary parts. A data type also represents 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.

Classes of data types

Primitive data types[edit]

Primitive data types are typically types that are built-in or basic to a language implementation.

Machine data types[edit]

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 usually 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 2011, typically 32 or 64 bits).

Numeric types

Composite types[edit]

Composite types are derived from more than one primitive type. This can be done in a number of ways. The ways they are combined are called data structures. Composing a primitive type into a compound type generally results in a new type, e.g. array-of-integer is a different type to integer.

  • An array stores a number of elements of the same type in a specific order. They are accessed randomly using an integer to specify which element is required (although the elements may be of almost any type). Arrays may be fixed-length or expandable.

    • list is similar to an array, but its contents are strung together by a series of references to the next element.
  • Record (also called tuple or struct) Records are among the simplest data structures. A record is a value that contains other values, typically in fixed number and sequence and typically indexed by names. The elements of records are usually called fields or members.
  • Union. A union type definition will specify which of a number of permitted primitive types may be stored in its instances, e.g. "float or long integer". Contrast with a record, which could be defined to contain a float and an integer; whereas, in a union, there is only one type allowed at a time.
    • tagged union (also called a variant, variant record, discriminated union, or disjoint union) contains an additional field indicating its current type for enhanced type safety.
  • set is an abstract data structure that can store certain values, without any particular order, and no repeated values. Values themselves are not retrieved from sets, rather one tests a value for membership to obtain a boolean "in" or "not in".
  • An object contains a number of data fields, like a record, and also a number of subroutines for accessing or modifying them, called methods.

Many others are possible, but they tend to be further variations and compounds of the above.

Enumerations[edit]

The enumerated type has distinct values, which can be compared and assigned, but which do not necessarily have any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.

String and text types

Other types[edit]

Types can be based on, or derived from, the basic types explained above. In some languages, such as C, functions have a type derived from the type of their return value.

Pointers and references[edit]

The main non-composite, derived type is the pointer, a data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memoryusing its address. It is a primitive kind of reference. (In everyday terms, a page number in a book could be considered a piece of data that refers to another one). Pointers are often stored in a format similar to an integer; however, attempting to dereference or "look up" a pointer whose value was never a valid memory address would cause a program to crash. To ameliorate this potential problem, pointers are considered a separate type to the type of data they point to, even if the underlying representation is the same.

Function types[edit]

Main article: Function type
 

Abstract data types[edit]

Any type that does not specify an implementation is an abstract data type. For instance, a stack (which is an abstract type) can be implemented as an array (a contiguous block of memory containing multiple values), or as a linked list (a set of non-contiguous memory blocks linked by pointers).

Abstract types can be handled by code that does not know or "care" what underlying types are contained in them. Programming that is agnostic about concrete data types is called generic programming. Arrays and records can also contain underlying types, but are considered concrete because they specify how their contents or elements are laid out in memory.

Examples include:

Type systems[edit]

type system associates types with computed values. By examining the flow of these values, a type system attempts to prove that no type errors can occur. The type system in question determines what constitutes a type error, but a type system generally seeks to guarantee that operations expecting a certain kind of value are not used with values for which that operation does not make sense.

compiler may use the static type of a value to optimize the storage it needs and the choice of algorithms for operations on the value. In many C compilers the floatdata type, for example, is represented in 32 bits, in accord with the IEEE specification for single-precision floating point numbers. They will thus use floating-point-specific microprocessor operations on those values (floating-point addition, multiplication, etc.).

The depth of type constraints and the manner of their evaluation affect the typing of the language. A programming language may further associate an operation with varying concrete algorithms on each type in the case of type polymorphismType theory is the study of type systems, although the concrete type systems of programming languages originate from practical issues of computer architecture, compiler implementation, and language design.

Type systems may be variously static or dynamicstrong or weak typing, and so forth.

https://en.wikipedia.org/wiki/Data_type

最新文章

  1. angular自己最近学的一种筛选方法
  2. 一句话在网页右上角加一个精致下拉框:forkme on github
  3. Linux学习之二——档案与目录的属性和权限
  4. Javascript获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
  5. nyoj 44 子串和
  6. linux下C和shell调用的popen函数
  7. HDU 2461 Rectangles#容斥原理
  8. 201521123009《Java程序设计》第14周学习总结
  9. [HNOI 2003]消防局的设立
  10. jenkins定位GitLab推送的最新Webhook中push event来自哪一个分支
  11. redis的两种安装方法
  12. leetcode — symmetric-tree
  13. jQuery使用(十):jQuery实例方法之位置、坐标、图形(BOM)
  14. impala和kudu使用的小细节
  15. xpath, urllib
  16. Codeforces1076D. Edge Deletion(最短路树+bfs)
  17. Win8.1/win10安装photoshop软件提示please uninstall and reinstall the product如何解决
  18. Mongodb主从复制/ 副本集/分片集群介绍
  19. java之httpClient 3.x、AsyncHttpClient1.9.x使用总结
  20. python大法好——字典、集合

热门文章

  1. day27-2 pandas模块
  2. 无法打开文件"CChart_d.lib"
  3. 如何设置root登录(滴滴云)
  4. centos7编译安装mysql5.6
  5. nyoj124-中位数
  6. 基于 SpringMVC——web.xml基本配置
  7. Hibernate 事务和并发控制
  8. wcf的Contract中name的使用
  9. Oracle-查看用户对象信息
  10. [ASP.NET]EF跨项目调用问题