在C语言编程语言的上下文中,数组数据结构与数组类型之间有什么区别? [英] What is the difference between an Array Data Structure and an Array Data-type in the context of a programming language like C?

查看:142
本文介绍了在C语言编程语言的上下文中,数组数据结构与数组类型之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维基百科区分数组数据结构



数组数据结构与在C语言的上下文中使用数组类型?



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



是数组数据结构还是数组数据类型?为什么?

解决方案

简答:我不怀疑作者的良好意图,但文章最令人困惑。


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



是数组数据结构还是数组数据类型?为什么?


都是。本文中讨论的数组数据结构应该具体涉及到C中实现的数组。数组数据类型概念应该更抽象,但是C数组肯定是数组数据类型的一个实现。



长回答行为与实现的区别。如文章中所使用的那样,数组数据结构是指顺序存储在内存中的元素,以便您可以通过以下方式计算任何元素的地址:

  address =(base address)+(元素索引*单个元素的大小)

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



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



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


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


数组数据类型的定义是:


数组类型是数据类型这意味着描述
元素(值或变量)的集合,每个元素(值或变量)由运行时计算的一个或多个索引
选择


这并不意味着数组数据结构文章,这显然应该是关于数组的C风格实现,包括关联数组和在数组数据类型文章中更合适的其他资料。您可以通过阅读讨论页了解原因,特别是拆分文章的提案数组结构。这些文章唯一清楚的是,各位作者无法弥补对数组的定义和解释的集体思考。


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

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

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

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

解决方案

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}; ?

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.

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.

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.

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语言编程语言的上下文中,数组数据结构与数组类型之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆