问题描述
-
只是想知道一个字符串是一个左或右值。其他的文字(如整型,浮点,焦炭等)的左值或右值?
-
是一个函数左值或右值的返回值?
你如何分辨?
- 字符串文字是左值,但你不能改变它们
- 右值,但如果它是一个指针和非NULL,它指向的对象是到左值
C标准承认的原有条款主张的左的和的右键的如 L = R
;然而,它说想左值作为的定位符值的,这大概意味着你可以得到一个对象的地址,因此该对象有一个位置。 (见 6.3.2.1)。
同样的道理,这个标准已经放弃了长期右值,而只是使用,这几乎是所有内容,包括文字,如整型,字符,花车等。一名前pression的价值。此外,任何你可以用右值做可以用左值来完成,所以你能想到的所有左值的作为是右值。
Just wonder if a literal string is an lvalue or an rvalue. Are other literals (like int, float, char etc) lvalue or rvalue?
Is the return value of a function an lvalue or rvalue?
How do you tell the difference?
- string literals are lvalues, but you can't change them
- rvalue, but if it's a pointer and non-NULL, the object it points to is an lvalue
The C standard recognizes the original terms stood for left and right as in L = R
; however, it says to think of lvalue as locator value, which roughly means you can get the address of an object and therefore that object has a location. (See 6.3.2.1 in C99.)
By the same token, the standard has abandoned the term rvalue, and just uses "the value of an expression", which is practically everything, including literals such as ints, chars, floats, etc. Additionally, anything you can do with an rvalue can be done with an lvalue too, so you can think of all lvalues as being rvalues.
这篇关于是文字字符串和函数的返回值左值右值还是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!