Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
849 views
in Technique[技术] by (71.8m points)

arrays - What is the difference between a composite data type and a data structure?

I read that a character array in C is a composite data type because it is a sequence of characters, but then in Java a String is a class and Wikipedia says that a class is data structure, I am confused.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

"Data structure" is a very general term of theoretical computer science. Any technique for the organization of machine-manipulable data can be thought of as a data structure. Even a single machine integer is a data structure, because there's more than one way that the bits could be interpreted. Most often, though "data structure" is used to refer to the organization applied to a large collection of data: for instance, a binary tree, a hash table, a flat array, or a linked list. And usually when people talk about data structures they do it in generic terms, not specific to a particular programming language.

"Composite data type" is a term-of-art of C and related languages, meaning "any language data type that isn't a machine number", more or less. Composite data types are data structures, but not all data structures are composite data types -- machine numbers are too simple to be composite data types, and a complex data structure is likely to be built out of several composite data types.

"Class" is a term-of-art of object-oriented programming languages, referring to a data type that defines not only data but "methods" for manipulating the data. In C++, all class types are composite data types, but not all composite data types are class types (the others are "plain old data", or "POD", types).

"String" is the generic term for a data structure that holds a sequence of small machine integers that somehow represent text. Just about every programming language has some notion of a string, but no two of them are the same. Strings are by definition data structures. In the C family, strings are always composite data types, because a single machine integer is not big enough for more than a few characters. In object-oriented programming languages, strings are usually, but not always, class types.

I hope this at least advances you to a more sophisticated level of confusion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...