Subodh
Subodh

Reputation: 1403

Derived data type

Why is an array called a derived data type?

Upvotes: 1

Views: 4233

Answers (5)

Narendra N
Narendra N

Reputation: 1270

C provides us with mainly five generic/primary data types, Here are the types & their ranges.

  • char -128 to 127 - any ascii characters includes alphanumerics & special characters
  • int -32768 to +32767 - only numbers/integers
  • float 3.4 e-38 to 3.4 e+38
  • double 1.7 e-308 to 1.7 e+308
  • void notapplicable

In case, if any of the above are not sufficient for representing any type for your problem, C has provided us with compound types like struct where you can defined your own types.

For eg: Fractions. To represent Fraction we need two integers, one for the numerator & second for the denominator.

So, we define a strcuture like below

typedef struct {
      int numer;
      int denom;
} fraction;

And from now, we can start using fraction to declare any new variable. fraction, here is a user-defined data type also referred some times as derived data type.

I am not aware that arrays are also referred as data types. To my knowledge, Array is a collection of finite number of elements of same data type, where each element is accessed by an index ranging from 0 to n-1, where n is no. of elements in the array.

With this defintion, I am not sure whether Arrays can be classified as derived data types. Like you, I am also waiting for a reason if at all they are classifed as derived data types.

Upvotes: 1

Daniel Daranas
Daniel Daranas

Reputation: 22634

The reason is that they are derived from the fundamental data types. (Actually, the version of the standard I looked up puts them under Compound types.)

Upvotes: 7

Roopesh Majeti
Roopesh Majeti

Reputation: 554

None of the base datatypes provide u to store more than 1 value [ Eg : int, char, float etc ] An array is nothing but, an extended form of the base data type, holding N items of the base data type. So, due to this, array is called the derived data type.

Upvotes: 0

anon
anon

Reputation:

The term does not appear in the C++ Standard, as far as i can determine. Where did you read it?

Upvotes: 3

Related Questions