Data type-数据类型

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

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

原文地址:https://www.cnblogs.com/feng9exe/p/8313236.html

时间: 2024-11-25 16:00:42

Data type-数据类型的相关文章

JAVA 1.2(原生数据类型 Primitive Data Type)

1. Java的数据类型分为2类 >> 原生数据类型(primitive data type) >> 引用数据类型(reference data type) 3. 常量和变量 常量: 所谓常量,就是值不会变化的量: 变量,就是值可以变化的量. 4. 如何定义和使用变量? int a; //变量的申明 a = 10; // 变量的初始化 int b = 20; // 变量的申明和初始化 注意事项: 如果没有初始化会出以下结果: 在Java中的== 和= 的区别: =  代表的是赋值操

ADT(Abstract Data Type)抽象数据类型

ADT(Abstract Data Type)抽象数据类型 为了便于理解,以复数为例: (1)定义: ADT Complex{ 数据对象:D={e1,e2|e1,e2为实数} 数据关系:S={<e1,e2>|e1是实部,e2是虚部} 基本操作: Creat(&C , x, y) GetReal(C) GetImage(C) Add(c1,c2) Sub(C1,C2) } ADT Complex; (2)表示: typedef struct{ float Realpart; float

数据类型(data type)

基本数据类型(primitive data type):字符型(2个字节),布尔型(一位),byte(1个字节),short(两个字节),int(4个字节),long(8个字节),float(2个字节),double(8个字节) 引用数据类型:4个字节 原文地址:https://www.cnblogs.com/jiaxin2019/p/10502446.html

C++数据类型(data type)介绍

在编写程序时,数据类型(data type)定义了使用存储空间的(内存)的方式. 程序员通过定义数据类型(data type),告诉特定存储空间这里要存储的数据类型是什么,以及你即将操作他的方式.(注:存储空间有:堆存储,栈,静态存储等,后面再仔细去研究) 1.数据类型可以是内部的或者抽象的. 内建数据类型: 内建数据类型是编译器可以理解的数据类型,直接与编译器关联.C++在这里几乎完全继承了C 的数据类型.或者称为基本数据类型 抽象数据类型: 可以先理解为一个类(C++灵魂的精髓,数据类型:类

【Agile Pair Coding】Data Type Mapping

介绍 今天下午用了1个小时左右,和同事Agile Pair Coding敏捷开发了一把,感觉挺爽的. Agile Pair Coding给我们带来的直接好处是:相互不浪费时间,高效:idea很快达成共识,不纠结于无谓的讨论:idea立马coding,不沉迷于头脑风暴:代码更严谨:重构概率大:加深基情:相互学习,相互欣赏,相互指正:避免无知,避免自我感觉良好...... 代码主要实现:从所有类型文件中,得到所有NE类型下的所有Object类型下的所有属性的数据类型. 当然,本文只是一个短时间内的D

ADT (Abstract Data Type)

抽象数据类型 ADT (Abstract Data Type) 是一个实现包括储存数据元素的存储结构以及实现基本操作的算法.在这个数据抽象思想中,数据类型的定义和它的实现是分开的,这在软件设计中是一个重要的概念.这使得只研究和使用它的结构而不用考虑它的实现细节成为可能. ADT包括数据数据元素,数据关系以及相关的操作. 即ADT { 数据对象:(数据元素集合) 数据关系:(数据关系二元组结合) 基本操作:(操作函数的罗列) }

salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema Builder 或者build-->schema Builder进入: 2.采用force.com Explorer通过自己写查询语句来查询数据. 此链接为force.com Explorer的下载链接:  http://force-com-explorer-beta.software.infor

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. 跟踪一下,当遇上一个空值时,它并没有真正是给一个空值给数据库,而是Datetime的最小值"1/1/0001 12:00:00 AM" 在两个文本框都是空值时,跟

Data Struct and Data Type

数据结构.数据类型 在看Java的HashMap之前,插播一点重要的数据结构要点. 1. 数据结构(data structure) 数据结构表达的是:用什么样的结构,组织一类数据. 分为逻辑结构和物理结构: 基本的逻辑结构有:集合.线性结构.树形结构.图: 物理结构:顺序存储.链式存储: 2. 数据类型(data type) 数据类型是和数据结构密切相关的,它是:值的集合和定义在这个值集上的一组操作的总称. 例如:c语言中的一种数据类型:整型变量,其值集为某个区间上的整数,定义在这些整数上的操作

Python报错:TypeError: data type not understood

K-Means聚类算法 def randCent(dataSet, k): m, n = dataSet.shape # numpy中的shape函数的返回一个矩阵的规模,即是几行几列 centrodids = np.zeros(k, n) for i in range(k): index = int(np.random.uniform(0, m)) # centrodids[i, :] = dataSet[index, :] return centrodids 报错TypeError: dat