本文介绍了在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.

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:

while the definition given for array data type is:

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

10-28 09:11