I know the fundamental data types in C - char, int, float etc. But What exactly are derived data types in C language?
-
http://stackoverflow.com/questions/660083/derived-classes-in-c-what-is-your-favorite-method – Mitch Wheat May 17 '11 at 02:05
5 Answers
6.2.5.20 of the standard (well, a draft; hooray free :) covers derived types:
20 Any number of derived types can be constructed from the object, function, and incomplete types, as follows:
-- An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type isT
, the array type is sometimes called array ofT
. The construction of an array type from an element type is called array type derivation.
-- A structure type describes a sequentially allocated nonempty set of member objects (and, in certain circumstances, an incomplete array), each of which has an optionally specified name and possibly distinct type.
-- A union type describes an overlapping nonempty set of member objects, each of which has an optionally specified name and possibly distinct type.
-- A function type describes a function with specified return type. A function type is characterized by its return type and the number and types of its parameters. A function type is said to be derived from its return type, and if its return type isT
, the function type is sometimes called function returningT
. The construction of a function type from a return type is called function type derivation.
-- A pointer type may be derived from a function type, an object type, or an incomplete type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced typeT
is sometimes called pointer toT
. The construction of a pointer type from a referenced type is called pointer type derivation.These methods of constructing derived types can be applied recursively.
Data types that are derived from fundamental data types are called derived data types. Derived data types don't create a new data type but,instead they add some functionality to the basic data types.
In C, two derived data type are : Array & Pointer.
Array : An array is a collection of variables of same type. They are stored in contagious memory allocation.
e.g
int a[10];
char chi [20];
Pointer :
A pointer is a special variable that holds a memory address (location in memory) of another variable.
int i=10;
int *j;
j=&i;
Here, j is a integer pointer as it holds an address of an integer variable i.

- 53,625
- 36
- 139
- 164
-
@roadrunner: i don't think that's what the poster is referring to. – Mitch Wheat May 17 '11 at 02:12
-
@Mitch Wheat : Don't get me wrong. But [I know the fundamental data types in C - char, int, float etc. But What exactly are derived data types in C language?] .... What does this suggest ? He wants to know about the available derived data types in C. – Saurabh Gokhale May 17 '11 at 02:14
-
@Mitch Wheat :Waiting till ! Let the OP speak up what exactly he wants. – Saurabh Gokhale May 17 '11 at 02:15
-
@roadrunner: see this: http://stackoverflow.com/questions/660083/derived-classes-in-c-what-is-your-favorite-method – Mitch Wheat May 17 '11 at 02:16
-
@Mitch : Yes, I already saw that link, posted in comments sec of Question. But, does he speak about that ? Well again, let's wait till OP speaks up. A lot of confusion ! :| – Saurabh Gokhale May 17 '11 at 02:18
-
There is no confusion. Poster asked "What exactly are derived data types in C", that's not what your answer describes. – Mitch Wheat May 17 '11 at 02:21
-
I feel there's some confusion. But, why the OP is not speaking about ? He should tell whether this is what he wanted ? If its incorrect, I will delete it. – Saurabh Gokhale May 17 '11 at 02:24
-
A pointer is a memory location, not a derived type. An array is simply a collection laid out in contiguous memory (note not contagious memory!) – Mitch Wheat May 17 '11 at 02:33
-
that's exactly what I wanted to know as a beginner in C.. It will help me move on .. thanks guys.. you are a big help.. – KawaiKx May 17 '11 at 02:43
Derived data type is nothing but it constructed from fundamental data type . example is pointer,structure,union etc. int i; int*ptr; ptr = &i; 'i' is variable of type an integer it is base data type. that's why pointer must be based data type.

- 31
- 2
A derived data type is a complex classification that identifies one or various data types and is made up of simpler data types called primitive data types. Derived data types have advanced properties and uses far beyond those of the basic primitive data types that operate as their essential building blocks.

- 11
- 1
Derived data types are derived from fundamental data types(ie: int, float, char, double,void). They don't create a new data type but use fundamental data type to add extra feature. Ex: Array: An Array is collection of variables of same type. Hence array is an derived data type.

- 639
- 10
- 17