Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an Array Data Structure and an Array Data-type in the context of a programming language like 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?

like image 961
user366312 Avatar asked Dec 04 '11 14:12

user366312


People also ask

What is the difference between array and structure in C programming?

Conclusion. Array and Structure are two important concepts in C programming. The programmer can directly declare an array whereas structure is a user-defined data type. The difference between Array and Structure in C programming is that the array helps to store a collection of elements of the same data type while the structure helps ...

What is an array type?

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

What is an array data structure?

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:

What is difference between data type and data structure in C++?

Data Type is the kind or form of a variable which is being used throughout the program. It defines that the particular variable will assign the values of the given data type only. Data Structure is the collection of different kinds of data. That entire data can be represented using an object and can be used throughout the entire program.


2 Answers

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.

like image 100
Caleb Avatar answered Sep 28 '22 16:09

Caleb


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).

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

like image 44
Oliver Charlesworth Avatar answered Sep 28 '22 15:09

Oliver Charlesworth