C语言 C和派生数据类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6025465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C and derived data types?
提问by KawaiKx
I know the fundamental data types in C- char, int, float etc. But What exactly are derived data types in Clanguage?
我知道C 中的基本数据类型- char、int、float 等。但是C语言中的派生数据类型究竟是什么?
回答by sarnold
6.2.5.20 of the standard (well, a draft; hooray free :)covers derived types:
标准的6.2.5.20 (好吧,草稿;万岁免费:)涵盖了派生类型:
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.
20 可以从对象、函数和不完整类型构造任意数量的派生类型,如下所示:
-- 数组类型描述具有特定成员对象类型的连续分配的非空对象集,称为元素类型。数组类型的特征在于它们的元素类型和数组中的元素数量。一个数组类型据说是从它的元素类型派生出来的,如果它的元素类型是T,这个数组类型有时被称为数组的T。从元素类型构造数组类型称为数组类型派生。
-- 结构类型描述了一组按顺序分配的非空成员对象(并且在某些情况下是不完整的数组),每个对象都有一个可选的指定名称和可能不同的类型。
-- 联合类型描述了一组重叠的非空成员对象,每个成员对象都有一个可选的指定名称和可能不同的类型。
-- 函数类型描述了具有指定返回类型的函数。函数类型的特征在于其返回类型以及其参数的数量和类型。一个函数类型据说是从它的返回类型派生出来的,如果它的返回类型是T,则该函数类型有时称为函数返回T. 从返回类型构造函数类型称为函数类型派生。
-- 指针类型可以派生自函数类型、对象类型或不完整类型,称为引用类型。指针类型描述了一个对象,其值提供对被引用类型的实体的引用。从引用类型派生的指针类型T有时称为指向 的指针T。从引用类型构造指针类型称为指针类型派生。这些构造派生类型的方法可以递归应用。
回答by sgokhales
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.
在 C 中,两种派生的数据类型是:数组和指针。
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.
这里,j 是一个整数指针,因为它保存了一个整数变量 i 的地址。
回答by shivraj choudhary
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.
派生数据类型只不过是由基本数据类型构造而成。例如指针、结构、联合等。 int i; int*ptr; ptr = &i; 'i' 是一个整数类型的变量,它是基本数据类型。这就是为什么指针必须是基于数据类型的原因。
回答by Harika Indugu
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.
派生数据类型是一种复杂的分类,用于标识一种或多种数据类型,并由称为原始数据类型的更简单的数据类型组成。派生数据类型具有高级属性,其用途远远超出作为其基本构建块运行的基本原始数据类型。
回答by vadiraj jahagirdar
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.
派生数据类型源自基本数据类型(即:int、float、char、double、void)。他们不会创建新的数据类型,而是使用基本数据类型来添加额外的功能。例如:数组:数组是相同类型变量的集合。因此数组是派生的数据类型。

