数组的结尾 [英] end of array

查看:163
本文介绍了数组的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有

char数组[10];


C允许获取数组[10]的地址(即& array [10]是有效的)

虽然元素数组[10]无法访问。


这是否允许在二进制搜索方法中使用(如K& R

第二版第137页)或者还有其他原因吗?

Suppose we have
char array[10];

C allows taking the address of array[10] (ie &array[10] is valid)
though the element array[10] cannot be accessed.

Is this allowed for use in binary search method (as given in K & R
second edition page 137) or is there any other reason ?

推荐答案

su ************** @ yahoo.com

假设我们有

char数组[10];


C允许数组[10]的地址(即&数组[10]有效)

虽然无法访问元素数组[10]。


这是允许在二进制搜索方法中使用(如K& R

第二版第137页中所述)或者还有其他原因吗?
Suppose we have
char array[10];

C allows taking the address of array[10] (ie &array[10] is valid)
though the element array[10] cannot be accessed.

Is this allowed for use in binary search method (as given in K & R
second edition page 137) or is there any other reason ?



这是允许的,因为某些惯用循环结构变得更容易

如果允许最后一个数组结束。着名的strcpy循环

就是一个例子。

It''s allowed because certain idiomatic loop constructs are made easier
if it was allowed to end up one past an array. The famous strcpy loop
is an example.


3月4日下午12:57,subramanian10 ... @ yahoo.com,印度"

< subramanian10 ... @ yahoo.comwrote:
On Mar 4, 12:57 pm, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:

假设我们有

char数组[10];


C允许获取数组[10]的地址(即&数组[10]有效)

虽然无法访问元素数组[10]。


这是否允许在二进制搜索方法中使用(如K& R

第二版中所示)第137页)或者还有其他原因吗?
Suppose we have
char array[10];

C allows taking the address of array[10] (ie &array[10] is valid)
though the element array[10] cannot be accessed.

Is this allowed for use in binary search method (as given in K & R
second edition page 137) or is there any other reason ?



C精神的一个重要方面是信任程序员。 C

让你有能力做任何你想要的事情(分段错误或

类似于操作系统给你的东西,而不是C)。 C被设计为
因为它最初是用来编写Unix内核的,这个

利基确定C不能太复杂而且不能隐藏某些东西

behide程序员。


你当然可以自由使用任何这样的功能,但C不能

保证是对的。确保'对你的工作是正确的。

One important facet of C spirit is that "Trust the programmer." C
gives you the power to do _nearly_ whatever you want (Segment fault or
something like that is what the OS gives you, not C). C is designed
for that because it was used to write the Unix kernel originally, this
niche determines C can''t be too complex and can''t hide something
behide programmers.

You can, of course, use any feature like that freely, but C can''t
guarantee that will be right. Making sure that''s right is your work.



这是允许的,因为某些惯用语循环结构是

变得更容易

如果允许最后一个数组结束。着名的

strcpy循环就是一个例子。
It''s allowed because certain idiomatic loop constructs are
made easier
if it was allowed to end up one past an array. The famous
strcpy loop is an example.



你说的不是指针的一个例子吗?


有了数组,为什么允许

Isn''t what you have mentioned, an example of pointer ?

With array, why is it allowed


这篇关于数组的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆