什么不能在c中添加指针? [英] What can't you add pointers in c?

查看:78
本文介绍了什么不能在c中添加指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么能减去指针,但你不能添加它们?

解决方案

这是什么意思的总和两个指针?


但减法你得到两个指针的偏移量。偏移

值可能有用。

grocery_stocker写道:

为什么你可以减去指针,但你不能添加它们?



文章< 11 ********************** @ o13g2000cwo。 googlegroups .com>,

grocery_stocker< cd ***** @ gmail.com>写道:

:你怎么能减去指针,但你不能添加它们?


你可以添加指针和整数(只要你保持

对象内。)


如果你 - 可以添加两个指针,你期望

结果是什么类型的?甚至假设我们约束了相同类型的两个指针

,并限制无法添加void *

然后如果结果与两个指针的类型相同:


然后可以添加第三个指针,第四个指针,

除非有一个限制次数

可以添加相同的指针,然后必须开始定义乘法指针的含义...然后

必须定义划分指针是什么意思;

那么你也想要指针模数。如果你打算用b
划分指针,你就会进行四舍五入和截断

问题。


And如果你已经设法找出所有这些的明智含义

,那么你可能还发现了一个明智的

意思是组合(加法,乘法)指针

和浮点数,你可以继续

并定义指针对数和复指针算术

和傅里叶变换指针...

-

我们*还有*


grocery_stocker< cd * ****@gmail.com>写道:

你怎么能减去指针,但你不能添加它们?




可能出于同样的原因你的自行车不能飞 - 它不是为它设计的b $ b,因为制造商认为大多数

无论如何都会骑在地上。

虽然在指针的情况下是 - 运算符被称为减法,

什么是*实际*被减去的不是指针本身,

但是指针所指向的数组元素的索引。


-

Stan Tobias

mailx`echo si *** @FamOuS.BedBuG.pAlS.INVA LID | sed s / [[:upper:]] // g`


How come you can subtract pointers, but you cannot add them?

解决方案

what''s meaning the sum of the two pointers?

but subtraction you get the offset of the two pointers. the offset
value may be useful.
grocery_stocker wrote:

How come you can subtract pointers, but you cannot add them?




In article <11**********************@o13g2000cwo.googlegroups .com>,
grocery_stocker <cd*****@gmail.com> wrote:
:How come you can subtract pointers, but you cannot add them?

You can add pointers and integers (provided that you stay
within the object.)

If you -could- add two pointers, what type would you expect the
result to be? Even presuming we constrain to two pointers
of the same type, and constrain that void* cannot be added,
then if the result was of the same type as the two pointers:

Then a third pointer could be added on, and a fourth pointer,
and unless one placed restrictions on the number of times
the same pointer could be added in, one would then have to
start defining what it meant to multiply pointers... and then
one would have to define what it was to divide pointers;
then you''d want pointer modulo as well. If you are going to
divide pointers, you''d hae to get into rounding and truncation
issues.

And if you''ve managed to figure out sensible meanings
for all of those, then you''ve probably also found a sensible
meaning for combining (addtion, multiplication) of pointers
and floating point numbers, and you might as well go ahead
and define pointer logarithms and complex pointer arithmetic
and fourier transforms of pointers...
--
Are we *there* yet??


grocery_stocker <cd*****@gmail.com> wrote:

How come you can subtract pointers, but you cannot add them?



Probably for the same reason your bicycle cannot fly - it wasn''t
designed for it, because the makers thought that the majority
would ride it on the ground anyway.

Although in case of pointers the "-" operator is called "subtraction",
what is *really* being subtracted is not the pointers themselves,
but the indices of array elements to which the pointers point to.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`


这篇关于什么不能在c中添加指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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