C语言数组下标为何从0开始

        Many other features, besides the type system, were put in C for the C compiler-writer's benefit (and
why not, since C compiler-writers were the chief customers for the first few years). Features of C that
seem to have evolved with the compiler-writer in mind are:
• Arrays start at 0 rather than 1. Most people start counting at 1, rather than zero. Compilerwriters
start with zero because we're used to thinking in terms of offsets. This is sometimes
tough on non-compiler-writers; although a[100] appears in the definition of an array, you'd
better not store any data at a[100], since a[0] to a[99] is the extent of the array.

        说白了就是除了类型系统之外,C的许多特征是为了方便编译器设计者而建立的(为什么不呢?开始几年C语言的主要客户就是哪些编译器设计者).数组下标从0而不是从1开始也是根据编译器设计者的思路而来的,因为偏移量的概念在他们心中已是根深蒂固.但这种设计让非编译器设计者感觉很别扭,他们可能会在一个定义的a[10]的a[10]存储数据,导致有名的一位偏移(one-bit offset)错误.

  java为何下标也从0开始呢,估计是考虑到习惯性问题.C/C++程序员被固化成下标从0开始后,想更改它也是件费劲事.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值