gpt4 book ai didi

c++ - 在 C++ 中,将取消引用的后递增指针分配给另一个取消引用的后递增指针的结果是什么?

转载 作者:行者123 更新时间:2023-12-03 06:51:46 25 4
gpt4 key购买 nike

我在 c++ 中遇到了与以下类似的代码,但我不确定它到底做了什么。

*x++ = *y++;
xy是对 uint32 的引用s。
我明白 ++是后增量运算符, *取消引用,但我仍然不确定这到底是做什么的。

最佳答案

C++ 标准 - 7.6.1.6 递增和递减 expr.post.incr
你的表情*x++ = *y++;应用后缀运算符 ++指向每个指针 xy 来自 *x = *y; 的分配发生。本质上,每个操作数的值都是应用任何增量之前的值。在值计算之后应用增量。
标准语言是:

1 The value of a postfix ++ expression is the value of its operand.

[Note 1: The value obtained is a copy of the original value. — endnote]

The operand shall be a modifiable lvalue. ... The value of the operandobject is modified(defns.access) by adding 1 toit. The value computation of the ++ expression is sequenced before themodification of the operand object. ...

2 The operand of postfix -- is decremented analogously to thepostfix ++ operator.


7.6.1.6 Increment and decrement - expr.post.incr
C 标准中的等效部分是 6.5.2.4 Postfix increment and decrement operators
如果您有任何其他问题,请告诉我。

关于c++ - 在 C++ 中,将取消引用的后递增指针分配给另一个取消引用的后递增指针的结果是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64657068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com