c语言中数组为何无法赋值,为什么不存在数组赋值操作但是C语言中的结构赋值呢?...

对于历史信息,这可能很有趣:

http://cm.bell-labs.com/who/dmr/chist.html

在B中,声明一个数组会为数组留出内存,就像C一样,但是为变量提供的名称用于定义指向数组的指针. Ritchie在C中改变了这个,所以名字“是”数组,但在使用时可以衰减为指针:

The rule, which survives in today’s C, is that values of array type

are converted, when they appear in expressions, into pointers to the

first of the objects making up the array.

This invention enabled most existing B code to continue to work,

despite the underlying shift in the language’s semantics. The few

programs that assigned new values to an array name to adjust its

origin—possible in B and BCPL, meaningless in C—were easily repaired.

如果在那个早期阶段,Ritchie已经定义了a = b来复制数组,那么他试图从B端口移植到C的代码就不那么容易修复了.正如他所定义的那样,该代码会产生错误,他可以修复它.如果他让C复制数组,那么他就会默默地改变代码的含义来复制数组,而不是重新设置用于访问数组的名称.

还有一个问题,“为什么自40年以来没有添加这个功能”,但我认为这就是为什么它不是从那里开始的.这本来是努力实现的,并且这种努力实际上会使C的早期版本更糟糕,因为稍微更难将B和BCPL代码移植到C.所以当然Ritchie没有这样做.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值