原帖由 unistd 于 2009-12-19 20:14 发表
C中的数组,仅仅是地址排列在一起的元素而已,不管是char、int还是复杂的struct数组,,仅仅是排列在一起的该类型大小的内存而已。数组的下标引用,仅仅是指针偏移的一种易读的形式!也可以说,数组在C中只是一个名字,简称而已。
原帖由 unistd 于 2009-12-19 20:34 发表
把字符串数组sizeof之后得到字符串的大小,只能说是C语言的一个特殊规定而已,我要是设计C语言的话,就不会做这个特殊规定,所有指针,一律返回该平台地址空间的字节大小
原帖由 unistd 于 2009-12-19 20:34 发表
把字符串数组sizeof之后得到字符串的大小,只能说是C语言的一个特殊规定而已,我要是设计C语言的话,就不会做这个特殊规定,所有指针,一律返回该平台地址空间的字节大小
原帖由 unistd 于 2009-12-19 20:34 发表
把字符串数组sizeof之后得到字符串的大小,只能说是C语言的一个特殊规定而已,我要是设计C语言的话,就不会做这个特殊规定,所有指针,一律返回该平台地址空间的字节大小
原帖由 unistd 于 2009-12-19 20:14 发表
所以说,那个关于数组名能不能减1的帖子,根本没有必要讨论那么多页,,数组名仅仅是一个指针而已,它的类型为数组的元素类型的指针,,只是通常这个指针指向第一个元素,而且为常量而已!
Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology. Most programming languages also allow the programmer to define additional data types, usually by combining multiple elements of other types and defining the valid operations of the new data type. For example, a programmer might create a new data type named "Person" that specifies that data interpreted as Person would include a name and a date of birth. Common data types may include:
* integers,
* floating-point numbers (decimals), and
* alphanumeric strings.
For example, in the Java programming language, the "int" type represents the set of 32-bit integers ranging in value from -2,147,483,648 to 2,147,483,647, as well as the operations that can be performed on integers, such as addition, subtraction, and multiplication. Colors, on the other hand, are represented by three bytes denoting the amounts each of red, green, and blue, and one string representing that color's name; allowable operations include addition and subtraction, but not multiplication.
A data type also represents a constraint placed upon the interpretation of data in a type system, describing representation, interpretation and structure of values or objects stored in computer memory. The type system uses data type information to check correctness of computer programs that access or manipulate the data.
原帖由 _UNISTD_H_ 于 2009-12-12 11:31 发表
靠,你吃饱了撑的有必要看汇编代码吗?
这是C语言规定的,又不是编译器规定的!
C可能是为了把问题简单化,并且提高效率,所以规定运算中类型至少提升到整形(整形一般和系统的字长相同)
至于gcc它怎么实现 ...
原帖由 unistd 于 2009-12-19 20:14 发表
从汇编、机器、硬件的角度思考C语言的问题,才是正确地道路。。而且几十年来,到了今天,计算机仍然是几十年前的体系结构,就算出来更多的java/net, C的这种工作方式仍然是有效的,,这是当代计算机软件的基础! ...
原帖由 unistd 于 2009-12-19 20:14 发表
在以他一些高级语言中,大都存在一种数组的类型,,该类型包含了若干元素,还有元素个数等其它属性。这些数组类型的对象是被当作一个整体来对待的。。。
但是在C中,可以说,不存在这种高级语言的数组类型
原帖由 ekek86 于 2009-12-21 10:26 发表
a也是char*类型,a的元素是char类型,所以a和b是同一类型。
sizeof( a)是编译器用“sizeof(char)*100”替换了sizeof( a)
原帖由 ekek86 于 2009-12-21 10:26 发表
a也是char*类型,a的元素是char类型,所以a和b是同一类型。
sizeof( a)是编译器用“sizeof(char)*100”替换了sizeof( a)
char a[100]; char *b; a = b; |
原帖由 unistd 于 2009-12-19 20:14 发表
在以他一些高级语言中,大都存在一种数组的类型,,该类型包含了若干元素,还有元素个数等其它属性。这些数组类型的对象是被当作一个整体来对待的。。。
但是在C中,可以说,不存在这种高级语言的数组类型, ...
原帖由 marlalee 于 2009-12-21 20:11 发表
自从学了指针以后,数组的东西就全扔了。
随着时间的推移,数组的东西已经全忘了,
现在只会用指针。
另外,C 被称为“高级汇编语言”,LZ的想法其实很正常,不值得大惊小怪。
原帖由 论坛热点 于 2009-12-21 19:20 发表
刚下课,过来看看又有多少傻子在此贴制造擦屁股纸!
我在第59楼说过“如果你想回帖,请先看#57楼”,傻子还真不少
先回复这个愚蠢的提问,一个个收拾。。。
char a[100];
char *b;
你问"那可以 ...
原帖由 zhujiang73 于 2009-12-21 20:32 发表
就算编译器做这傻事也只是让 100 个字节数据作废而已,不用搬运任何东西。
机器人的 ai 还是不行呀,我认为这个 id 是一个用 oioic 写的机器人。
原帖由 论坛热点 于 2009-12-21 20:39 发表
草,你是真傻还是装傻? 我认为你是真傻吧,这样我才有耐心回答。
如果这100字节里有有用数据呢?即使没有有用数据也须重新申请100字节的内存呀,傻子明白了么傻子
ps: 你一口一个oioic,你对o ...
原帖由 zhujiang73 于 2009-12-21 20:51 发表
我是真傻
> 如果这100字节里有有用数据呢?
保证这100 字节里没有有用数据是程序员的责任,不是 C 编译器的责任。
我对 oicc 感兴趣。
原帖由 论坛热点 于 2009-12-21 10:56 发表
char a[100];
char *b;
好了,这个才是正确的答案!!!前面那些回复浪费的纸张就只能留作擦屁股纸用了。
我宣布这个贴就此结束!LZ胜利赢了
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |