在像C这样的编程语言的上下文中,数组数据结构和数组数据类型之间有什么区别?

时间:2022-08-18 16:37:21

Wikipedia differentiates an Array Data Structure and an Array Data-type.

Wikipedia区分阵列数据结构和阵列数据类型。

What is the difference between an Array Data Structure and an Array Data-type in the context of a programming language like C?

在像C这样的编程语言的上下文中,数组数据结构和数组数据类型之间有什么区别?

What is this : int array[]={1, 2, 3, 4, 5}; ?

这是什么:int array [] = {1,2,3,4,5}; ?

Is it an Array Data Structure or an Array Data-type? Why?

它是阵列数据结构还是阵列数据类型?为什么?

4 个解决方案

#1


5  

Short answer: Do yourself a favor and just ignore both articles. I don't doubt the good intentions of the authors, but the articles are confusing at best.

简短的回答:帮自己一个忙,只是忽略这两篇文章。我不怀疑作者的善意,但文章充其量令人困惑。

What is this : int array[]={1, 2, 3, 4, 5}; ?

这是什么:int array [] = {1,2,3,4,5}; ?

Is it an Array Data Structure or an Array Data-type? Why?

它是阵列数据结构还是阵列数据类型?为什么?

It's both. The array data structure discussed in the article by that name is supposed to relate specifically to arrays as implemented in C. The array data type concept is supposed to be more abstract, but C arrays certainly are one implementation of array data type.

这两者都是。该文章中讨论的数组数据结构应该与C中实现的数组具体相关。数组数据类型概念应该更抽象,但C数组肯定是数组数据类型的一种实现。

Long answer: The difference those two articles consider is the difference between behavior and implementation. As used in the articles, array data structure refers to elements stored sequentially in memory, so that you can calculate the address of any element by:

答案很长:这两篇文章所考虑的差异是行为与实施之间的差异。正如文章中所使用的,数组数据结构是指按顺序存储在内存中的元素,因此您可以通过以下方式计算任何元素的地址:

address = (base address) + (element index * size of a single element)

where 'base address' is the address of the element at index 0.

其中'base address'是索引0处元素的地址。

Array data type, on the other hand, refers to any data type that provides a logical sequence of elements accessed by index. For example, C++ provides std::vector, and Objective-C provides NSArray and NSMutableArray, none of which are likely to be implemented as a contiguous sequence of elements in memory.

另一方面,数组数据类型是指提供由索引访问的元素的逻辑序列的任何数据类型。例如,C ++提供了std :: vector,而Objective-C提供了NSArray和NSMutableArray,其中没有一个可能被实现为内存中连续的元素序列。

The terminology used in the articles isn't very helpful. The definition given at the top of the array data structure article is:

文章中使用的术语不是很有用。数组数据结构文章顶部给出的定义是:

an array data structure or simply array is a data structure consisting of a collection of elements (values or variables), each identified by at least one index

数组数据结构或简单数组是由元素集合(值或变量)组成的数据结构,每个元素由至少一个索引标识

while the definition given for array data type is:

而为数组数据类型定义的是:

an array type is a data type that is meant to describe a collection of elements (values or variables), each selected by one or more indices that can be computed at run time

数组类型是一种数据类型,用于描述元素集合(值或变量),每个元素由一个或多个可在运行时计算的索引选择

It doesn't help that the array data structure article, which is apparently supposed to be about the C-style implementation of arrays, includes discussion of associative arrays and other material that would be far more appropriate in the array data type article. You can learn why this is by reading the discussion page, particularly Proposal to split the article and Array structure. The only thing that's clear about these articles is that the various authors can't make up their collective mind about how 'array' should be defined and explained.

数组数据结构文章(显然应该是关于数组的C风格实现)包括对关联数组和其他在数组数据类型文章中更合适的材料的讨论没有帮助。您可以通过阅读讨论页面来了解其原因,特别是分割文章和数组结构的提案。对这些文章唯一清楚的是,各种作者无法对如何定义和解释“数组”做出集体思考。

#2


4  

A type is something that the programmer sees; a data structure is how something is implemented behind the scenes. It's conceivable that an array type is implemented behind the scenes with e.g. a hashtable (this is the case for PHP, I think).

类型是程序员看到的东西;数据结构是在幕后实现某些东西的方式。可以想象,在幕后实现阵列类型,例如,哈希表(我认为这是PHP的情况)。

In C, there is no distinction; an array type must be implemented with a contiguous block of memory.

在C中,没有区别;必须使用连续的内存块实现数组类型。

#3


0  

The structure of your array determines how the array is implemented (storage and access), the data type refers to the types of data contain within the array. For your reading pleasure read each of these links.

数组的结构决定了数组的实现方式(存储和访问),数据类型是指数组中包含的数据类型。为了您的阅读乐趣,请阅读每个链接。

#4


-1  

Brackets [] is how you designate an Array Data Type in C

Brackets []是您在C中指定阵列数据类型的方式

Similary, * is how you designate a Pointer Data Type in C

类似,*是你如何在C中指定指针数据类型

int array[]={1, 2, 3, 4, 5}; is an example of an Array Data Structure in C

int array [] = {1,2,3,4,5};是C中的数组数据结构的示例

Specifically, you have defined a data structure which has 5 integers arranged contiguously, you have allocated sufficient memory on the stack for that data structure, and you have initialized that data structure with values 1, 2, 3, 4, 5.

具体来说,您已经定义了一个具有5个连续排列的整数的数据结构,您已在该堆栈上为该数据结构分配了足够的内存,并且已使用值1,2,3,4,5初始化该数据结构。

A Data Structure in C has a non-zero size which can be found by calling sizeof() on an instance of that structure.

C中的数据结构具有非零大小,可以通过在该结构的实例上调用sizeof()来找到它。

#1


5  

Short answer: Do yourself a favor and just ignore both articles. I don't doubt the good intentions of the authors, but the articles are confusing at best.

简短的回答:帮自己一个忙,只是忽略这两篇文章。我不怀疑作者的善意,但文章充其量令人困惑。

What is this : int array[]={1, 2, 3, 4, 5}; ?

这是什么:int array [] = {1,2,3,4,5}; ?

Is it an Array Data Structure or an Array Data-type? Why?

它是阵列数据结构还是阵列数据类型?为什么?

It's both. The array data structure discussed in the article by that name is supposed to relate specifically to arrays as implemented in C. The array data type concept is supposed to be more abstract, but C arrays certainly are one implementation of array data type.

这两者都是。该文章中讨论的数组数据结构应该与C中实现的数组具体相关。数组数据类型概念应该更抽象,但C数组肯定是数组数据类型的一种实现。

Long answer: The difference those two articles consider is the difference between behavior and implementation. As used in the articles, array data structure refers to elements stored sequentially in memory, so that you can calculate the address of any element by:

答案很长:这两篇文章所考虑的差异是行为与实施之间的差异。正如文章中所使用的,数组数据结构是指按顺序存储在内存中的元素,因此您可以通过以下方式计算任何元素的地址:

address = (base address) + (element index * size of a single element)

where 'base address' is the address of the element at index 0.

其中'base address'是索引0处元素的地址。

Array data type, on the other hand, refers to any data type that provides a logical sequence of elements accessed by index. For example, C++ provides std::vector, and Objective-C provides NSArray and NSMutableArray, none of which are likely to be implemented as a contiguous sequence of elements in memory.

另一方面,数组数据类型是指提供由索引访问的元素的逻辑序列的任何数据类型。例如,C ++提供了std :: vector,而Objective-C提供了NSArray和NSMutableArray,其中没有一个可能被实现为内存中连续的元素序列。

The terminology used in the articles isn't very helpful. The definition given at the top of the array data structure article is:

文章中使用的术语不是很有用。数组数据结构文章顶部给出的定义是:

an array data structure or simply array is a data structure consisting of a collection of elements (values or variables), each identified by at least one index

数组数据结构或简单数组是由元素集合(值或变量)组成的数据结构,每个元素由至少一个索引标识

while the definition given for array data type is:

而为数组数据类型定义的是:

an array type is a data type that is meant to describe a collection of elements (values or variables), each selected by one or more indices that can be computed at run time

数组类型是一种数据类型,用于描述元素集合(值或变量),每个元素由一个或多个可在运行时计算的索引选择

It doesn't help that the array data structure article, which is apparently supposed to be about the C-style implementation of arrays, includes discussion of associative arrays and other material that would be far more appropriate in the array data type article. You can learn why this is by reading the discussion page, particularly Proposal to split the article and Array structure. The only thing that's clear about these articles is that the various authors can't make up their collective mind about how 'array' should be defined and explained.

数组数据结构文章(显然应该是关于数组的C风格实现)包括对关联数组和其他在数组数据类型文章中更合适的材料的讨论没有帮助。您可以通过阅读讨论页面来了解其原因,特别是分割文章和数组结构的提案。对这些文章唯一清楚的是,各种作者无法对如何定义和解释“数组”做出集体思考。

#2


4  

A type is something that the programmer sees; a data structure is how something is implemented behind the scenes. It's conceivable that an array type is implemented behind the scenes with e.g. a hashtable (this is the case for PHP, I think).

类型是程序员看到的东西;数据结构是在幕后实现某些东西的方式。可以想象,在幕后实现阵列类型,例如,哈希表(我认为这是PHP的情况)。

In C, there is no distinction; an array type must be implemented with a contiguous block of memory.

在C中,没有区别;必须使用连续的内存块实现数组类型。

#3


0  

The structure of your array determines how the array is implemented (storage and access), the data type refers to the types of data contain within the array. For your reading pleasure read each of these links.

数组的结构决定了数组的实现方式(存储和访问),数据类型是指数组中包含的数据类型。为了您的阅读乐趣,请阅读每个链接。

#4


-1  

Brackets [] is how you designate an Array Data Type in C

Brackets []是您在C中指定阵列数据类型的方式

Similary, * is how you designate a Pointer Data Type in C

类似,*是你如何在C中指定指针数据类型

int array[]={1, 2, 3, 4, 5}; is an example of an Array Data Structure in C

int array [] = {1,2,3,4,5};是C中的数组数据结构的示例

Specifically, you have defined a data structure which has 5 integers arranged contiguously, you have allocated sufficient memory on the stack for that data structure, and you have initialized that data structure with values 1, 2, 3, 4, 5.

具体来说,您已经定义了一个具有5个连续排列的整数的数据结构,您已在该堆栈上为该数据结构分配了足够的内存,并且已使用值1,2,3,4,5初始化该数据结构。

A Data Structure in C has a non-zero size which can be found by calling sizeof() on an instance of that structure.

C中的数据结构具有非零大小,可以通过在该结构的实例上调用sizeof()来找到它。