6.2.5.20 of the standard (well, a draft; hooray free :) covers derived types:
Answer from sarnold on Stack Overflow20 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 typeTis 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.
Videos
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 typeTis 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.
Is int * a derived datatype or not?
It is a derived type from the object type int.
if we need to consider int * as a derived datatype, then just like e, f, g, h are variables of int datatype, all the variables a, b, c, d must be pointers pointing to int datatype, right?
If you will introduce the type int * as a type specifier as for example
typedef int * T;
then indeed in this declaration
T a, b, c, d;
all the declared variables have the type int *. Otherwise the symbol * is related to the declarator of the variable a in this declaration
int* a, b, c, d;
that may be rewritten like
int ( * a ), b, c, d;
Pay attention to that declaration is defined like (here is a partial definition of declaration):
declaration:
declaration-specifiers init-declarator-listopt ;
declaration-specifiers:
type-qualifier declaration-specifiersopt
init-declarator-list:
init-declarator
init-declarator-list , init-declarator
init-declarator:
declarator
declarator = initializer
That is in this declaration
int* a, b, c, d;
the common type specifier of all declarators is int and the declarator a has the form *a.
While in this declaration
T a, b, c, d;
the common type specifier is T that represents the derived pointer type int *.
That is the derived pointer type int * is being built from its referenced type int. The derived type int ** is being built from its referenced type int * and so on.
So for example passing by reference in C means passing an object indirectly through another object of its derived pointer type that references the type of the original object.
Ok. We have an fundamental datatypes (int, float, double,...) and we have an derived datatypes and we also have a derived datatypes(fundamental datatype with some extensions).
In your first example int* a, b, c, d; we have an a as a pointer to integer
but b, c, d are not pointers to the integers, because they are just integers !
So, yes you are right! int* is derived from the int.
Your confusion has started with taking b,c,d also as a pointers but they are not.
In C programming language during the variable declaration process if there is an *
between variable name and hers datatype than that variable is a pointer to hers
datatype.