C语言老师告诉我,数组 不是一种 数据类型,我觉得很纳闷,百思不得其解,大家帮忙指点一下。另外C语言到底有哪几种数据类型?

msdner 2004-09-21 04:40:20
如题,谢谢大家。
...全文
1275 70 打赏 收藏 转发到动态 举报
写回复
用AI写文章
70 条回复
切换为时间正序
请发表友善的回复…
发表回复
msdner 2004-09-26
  • 打赏
  • 举报
回复
分数不够,各位抱歉了,只能从头开始给分。
nanhaiyiou 2004-09-24
  • 打赏
  • 举报
回复
长见识
248406869 2004-09-24
  • 打赏
  • 举报
回复
楼主呀,快结贴吧。好有个位大侠都不要在顶了。这个问题大家已经解释的很清楚了,让他沉底吧。
cqhejun 2004-09-24
  • 打赏
  • 举报
回复
都是数据类型,基本数据类型和导出数据类型.
BluntBlade 2004-09-23
  • 打赏
  • 举报
回复
数组是用户定义类型。
结构、联合、类、枚举、指针、引用等等都是用户定义类型。
kinglonghr 2004-09-23
  • 打赏
  • 举报
回复
这问题有意义吗?

每次遇到这样的贴 up的人就暴多 一遇到算法方面的就都没气了
cpunion 2004-09-22
  • 打赏
  • 举报
回复
基本上不同意它是一种类型的说法,说它是一片连续内存空间还差不多。

我们常用的数据类型,都可以作为参数、返回值、引用、指针,而数组呢?作为参数和返回值,它要转化为指针。

不过这不是个很重要的问题,我又不写书,我只要知道它是干什么的就行了,是不是类型不归我管。
nicknide 2004-09-22
  • 打赏
  • 举报
回复
我个人认为的有点极端的看法:
数组确实不是类型,因为它连做UDT的资格都没有,谈何做基本语言类型。

原应是什么?很简单,C、C++是一种强类型语言,进行十分精确的型别匹配,而且在编译器默认的情况下是安全的型别匹配的(除非client自己刻意写非正常代码)。
但是如果加上数组这种类型,那么这个建立在型别上的安全性将崩溃……为什么?

如果class A是一个base class,而B是他的子类型,那么如果这样定义:
A a[]={b(0),b(1),b(2)};
这个时候就是非类型安全的了,因为B的大小和A是不同的,在数组上构造类成员是十分危险的举动,因为很有可能造成写溢出错误。指针相对来说好一点(不是指向一块内存的指针,而是单索引指针),支持安全的类型匹配。

因此,数组是不能作为内建数据类型来做的,因为它不够安全。


另,标准说法中,数组是数据结构,楼上的carambo(艰苦奋斗,挺过十月!)正确
carambo 2004-09-22
  • 打赏
  • 举报
回复
数组是一种数据结构!!!
freewuyang 2004-09-22
  • 打赏
  • 举报
回复
讨论这个东西跟讨论‘回’字有几种写法有什么区别?
你只需要知道的是数组是一个连续的内存空间,里边可以分成同样大小的n个单元,
而数组名字对编译器来讲包含的是这个空间的首地址,这就够了
MountLion 2004-09-22
  • 打赏
  • 举报
回复
你可以把它理解为一种类型,不过实际上是一个算式:)
短歌如风 2004-09-22
  • 打赏
  • 举报
回复
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.36) 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 is T, the
array type is sometimes called ‘‘array of T’’. 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 is T, the
function type is sometimes called ‘‘function returning T’’. The construction of a
function type from a return type is called ‘‘function type derivation’’.
— Apointer 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 type T is sometimes called ‘‘pointer to T’’. 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.
21 Arithmetic types and pointer types are collectively called scalar types. Array and
structure types are collectively called aggregate types.37)
22 An array type of unknown size is an incomplete type. It is completed, for an identifier of
that type, by specifying the size in a later declaration (with internal or external linkage).
A structure or union type of unknown content (as described in 6.7.2.3) is an incomplete
type. It is completed, for all declarations of that type, by declaring the same structure or
union tag with its defining content later in the same scope.
23 Array, function, and pointer types are collectively called derived declarator types. A
declarator type derivation from a type T is the construction of a derived declarator type
from T by the application of an array-type, a function-type, or a pointer-type derivation to
T.
24 A type is characterized by its type category, which is either the outermost derivation of a
derived type (as noted above in the construction of derived types), or the type itself if the
type consists of no derived types.
25 Any type so far mentioned is an unqualified type. Each unqualified type has several
qualified versions of its type,38) corresponding to the combinations of one, two, or all
three of the const, volatile, and restrict qualifiers. The qualified or unqualified
versions of a type are distinct types that belong to the same type category and have the
same representation and alignment requirements.39) A derived type is not qualified by the
qualifiers (if any) of the type from which it is derived.
26 A pointer to void shall have the same representation and alignment requirements as a
pointer to a character type.39) Similarly, pointers to qualified or unqualified versions of
compatible types shall have the same representation and alignment requirements. All
pointers to structure types shall have the same representation and alignment requirements
as each other. All pointers to union types shall have the same representation and
alignment requirements as each other. Pointers to other types need not have the same
representation or alignment requirements.
27 EXAMPLE 1 The type designated as ‘‘float *’’ has type ‘‘pointer to float’’. Its type category is
pointer, not a floating type. The const-qualified version of this type is designated as ‘‘float * const’’
whereas the type designated as ‘‘const float *’’ is not a qualified type — its type is ‘‘pointer to constqualified
float’’ and is a pointer to a qualified type.
28 EXAMPLE 2 The type designated as ‘‘struct tag (*[5])(float)’’ has type ‘‘array of pointer to
function returning struct tag’’. The array has length five and the function has a single parameter of type
float. Its type category is array.
短歌如风 2004-09-22
  • 打赏
  • 举报
回复
数组是一种C数据类型,属于“组合类型”。
1 The meaning of a value stored in an object or returned by a function is determined by the
type of the expression used to access it. (An identifier declared to be an object is the
simplest such expression; the type is specified in the declaration of the identifier.) Types
are partitioned into object types (types that fully describe objects), function types (types
that describe functions), and incomplete types (types that describe objects but lack
information needed to determine their sizes).
2 An object declared as type _Bool is large enough to store the values 0 and 1.
3 An object declared as type char is large enough to store any member of the basic
execution character set. If a member of the basic execution character set is stored in a
char object, its value is guaranteed to be positive. If any other character is stored in a
char object, the resulting value is implementation-defined but shall be within the range
of values that can be represented in that type.
4 There are five standard signed integer types, designated as signed char, short
int, int, long int, and long long int. (These and other types may be
designated in several additional ways, as described in 6.7.2.) There may also be
implementation-defined extended signed integer types.28) The standard and extended
signed integer types are collectively called signed integer types.29)
5 An object declared as type signed char occupies the same amount of storage as a
‘‘plain’’ char object. A ‘‘plain’’ int object has the natural size suggested by the
architecture of the execution environment (large enough to contain any value in the range
INT_MIN to INT_MAX as defined in the header <limits.h>).
6 For each of the signed integer types, there is a corresponding (but different) unsigned
integer type (designated with the keyword unsigned) that uses the same amount of
storage (including sign information) and has the same alignment requirements. The type
_Bool and the unsigned integer types that correspond to the standard signed integer
types are the standard unsigned integer types. The unsigned integer types that
correspond to the extended signed integer types are the extended unsigned integer types.
The standard and extended unsigned integer types are collectively called unsigned integer
types.30)
7 The standard signed integer types and standard unsigned integer types are collectively
called the standard integer types, the extended signed integer types and extended
unsigned integer types are collectively called the extended integer types.
8 For any two integer types with the same signedness and different integer conversion rank
(see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
subrange of the values of the other type.
9 The range of nonnegative values of a signed integer type is a subrange of the
corresponding unsigned integer type, and the representation of the same value in each
type is the same.31) A computation involving unsigned operands can never overflow,
because a result that cannot be represented by the resulting unsigned integer type is
reduced modulo the number that is one greater than the largest value that can be
represented by the resulting type.
10 There are three real floating types, designated as float, double, and long
double.32) The set of values of the type float is a subset of the set of values of the
type double; the set of values of the type double is a subset of the set of values of the
type long double.
11 There are three complex types, designated as float _Complex, double
_Complex, and long double _Complex.33) The real floating and complex types
are collectively called the floating types.
12 For each floating type there is a corresponding real type, which is always a real floating
type. For real floating types, it is the same type. For complex types, it is the type given
by deleting the keyword _Complex from the type name.
13 Each complex type has the same representation and alignment requirements as an array
type containing exactly two elements of the corresponding real type; the first element is
equal to the real part, and the second element to the imaginary part, of the complex
number.
14 The type char, the signed and unsigned integer types, and the floating types are
collectively called the basic types. Even if the implementation defines two or more basic
types to have the same representation, they are nevertheless different types.34)
15 The three types char, signed char, and unsigned char are collectively called
the character types. The implementation shall define char to have the same range,
representation, and behavior as either signed char or unsigned char.35)
16 An enumeration comprises a set of named integer constant values. Each distinct
enumeration constitutes a different enumerated type.
17 The type char, the signed and unsigned integer types, and the enumerated types are
collectively called integer types. The integer and real floating types are collectively called
real types.
18 Integer and floating types are collectively called arithmetic types. Each arithmetic type
belongs to one type domain: the real type domain comprises the real types, the complex
type domain comprises the complex types.
19 The void type comprises an empty set of values; it is an incomplete type that cannot be
completed.
zhangfjj 2004-09-22
  • 打赏
  • 举报
回复
数组是一种常用的构造类型,还有它的成员类型都是相同的。所以对数组类型的定义作了简化。
int a[10];

struct{
int a0;
int a1;
...
int a9;
}a;
这里结构体变量a有10个成员,

zhangfjj 2004-09-22
  • 打赏
  • 举报
回复
int a[10];
数组a的类型是int [10]。
迈克老狼0411 2004-09-22
  • 打赏
  • 举报
回复
老师是白痴 !这点我深有体会!还是找个写过程序的问问清楚!
Ardor007 2004-09-22
  • 打赏
  • 举报
回复
数组是构造类型。
ch_gufen 2004-09-22
  • 打赏
  • 举报
回复
靠,数组就是数组,数组中的每一个元素,才有数据类型。
int a[10]
a[1] 是 int 型的。但是a[10] 不是
Rail100 2004-09-22
  • 打赏
  • 举报
回复
嘿嘿,大家灌水也差不多了,楼主还是结贴吧。
vt 2004-09-22
  • 打赏
  • 举报
回复
是数据类型,这应该比较好理解的,如果你看过PASCAL的话,它里面更加明确
下面是一个示例
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
typedef int a3[3];
typedef int a4[4];
a3 a;
a4 b;
a[0]=1;
a[1]=2;
a[2]=3;
b[0]=5;
b[1]=6;
b[2]=7;
b[3]=8;
//a=b; 这句在dev c++里有下面的错误
//incompatible types in assignment of `int[4]' to `int[3]'
//应该很清楚了吧,是incompatible types: int[4] 和 int[3]
std::cout<<a[0]<<a[1]<<a[2]<<std::endl;
std::cout<<b[0]<<b[1]<<b[2]<<b[3];
system("PAUSE");
return 0;
}

加载更多回复(50)
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧