gpt4 book ai didi

c - 取消引用运算符返回什么?左值或右值

转载 作者:太空宇宙 更新时间:2023-11-04 04:19:41 25 4
gpt4 key购买 nike

取消引用运算符返回什么?左值或右值基于以下示例,因为增量运算符工作正常。需要相同的解释

// venukant
#include<stdio.h>
int main()
{
char arr[] = "gendafool";
char *p = arr;
++*p; // evaluated as ++(*p) but ++ requires a l-value
printf(" %c", *p); // prints h

return 0;
}

最佳答案

从 1999 C 标准开始,第 6.3.2.1 节,第 1 段以......开头

An lvalue is an expression with an object type or an incomplete type other than void;

然后引用脚注 53,其中说

The name ‘‘lvalue’’ comes originally from the assignment expression E1 = E2, in which the left operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an object ‘‘locator value’’. What is sometimes called ‘‘rvalue’’ is in this International Standard described as the ‘‘value of an expression’’.

An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary expression that is a pointer to an object, *E is an lvalue that designates the object to which E points.

在n1548(2011年标准草案)中,同样的para开头的措辞略有不同,但意思基本相同;

An lvalue is an expression (with an object type other than void )that potentially designates an object;

此段引用脚注 64,其内容与 1999 C 标准中的脚注 53 相同。

请记住,标准中的脚注不是规范性的 - 它们的目的是澄清和解释。

为了回答最初的问题,取消引用运算符 (*p) 产生一个左值。但是,表达式的值可以用作右值。

关于c - 取消引用运算符返回什么?左值或右值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47971200/

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