L-value represents the address of the value. "L" stands for the left side, because the address it is what is required when the variable appears on the left side of an assignment operation.
Questions tagged [lvalue]
661 questions
8
votes
2 answers
What language coined the term lvalue?
Was C the first programming language to use the term lvalue, or does it go further back? Note that I'm not talking about the general concept of "something on the left-hand side of an assignment statement" (which it has ceased to mean in C++ a long…

fredoverflow
- 256,549
- 94
- 388
- 662
8
votes
6 answers
Why myClassObj++++ doesn't incur a compile error : '++' needs l-value just as buildin type do?
Why myint++++ compiles fine with VS2008 compiler and gcc 3.42 compiler ?? I was expecting compiler say need lvalue, example see below.
struct MyInt
{
MyInt(int i):m_i(i){}
MyInt& operator++() //return reference, return a lvalue
{
…

RoundPi
- 5,819
- 7
- 49
- 75
8
votes
1 answer
Why can i assign a value to a rvalue reference?
I recently started learning about rvalues,lvalues, move semantics and I can't understands some conceps like rvalue refs .. why can I assign a value to a rvalue ref like : int&& x = 10;.. doesn't that mean that an rvalue ref is an lvalue(I tought…

Robert
- 125
- 5
8
votes
3 answers
What's the meaning of "identity" in the definition of value categories in C++
In short, you can just answer the part about identity, thanks. My main focus of this question is start from 2. about identity, I just tried to provide context/background of my current understanding so it may help you decide the depth when you're…

Kindred
- 1,229
- 14
- 41
8
votes
2 answers
C++ arrow type yields lvalue
According to the C++ Primer, C++ arrow operator yields an lvalue. Additionally decltype of an expression which yields an lvalue will result in a reference type. So why the following decltype does not result in a reference type.
struct MyStruct {
…

Nami
- 1,215
- 11
- 21
8
votes
3 answers
Expression must be Modifiable lvalue (char array)
I defined my struct as:
struct taxPayer{
char name[25];
long int socialSecNum;
float taxRate;
float income;
float taxes;
};
My main function contains:
taxPayer citizen1, citizen2;
citizen1.name = "Tim McGuiness";
citizen1.socialSecNum =…

Zack Sloan
- 133
- 1
- 1
- 8
8
votes
1 answer
Assigning a value to a constant syntax or semantic error?
Is the second line of code considered as a syntax error or a semantic error in C++?
int a = 7;
3 = a;
In standard C++ context-free grammar I found this statement syntactically valid.

Abdul Rehman
- 1,687
- 18
- 31
8
votes
2 answers
Return lvalue reference from temporary object
Is, returning an lvalue reference to *this, allowed when *this is an rvalue?
#include
#include
using namespace std;
class A {
public:
A& f() {
return *this;
}
string val() const {
return "works";
…

barsdeveloper
- 930
- 8
- 28
8
votes
5 answers
A legal array assignment. Is it possible?
After reading the chapter about structures in the K&R book I decided to make some tests to understand them better, so I wrote this piece of code:
#include
#include
struct test func(char *c);
struct test
{
int i ;
int j…

Farouq Jouti
- 1,657
- 9
- 15
8
votes
4 answers
invalid initialization of non-const reference of type 'int&' from a temporary of type 'int'
#include
using namespace std;
int fun(int &x)
{
return x;
}
int main()
{
cout << fun(10);
return 0;
}
Can anyone explain the reason of the error ?
Thanks

dark_shadow
- 3,503
- 11
- 56
- 81
7
votes
1 answer
Why does my function only work with lvalues?
I have a function that returns a lowercase string:
constexpr auto string_to_lower_case(const std::string& string) {
return string
| std::views::transform(std::tolower)
| std::views::transform([](const auto& ascii) { return…

camelopard
- 83
- 1
- 5
7
votes
2 answers
std::tie fails with "cannot bind non-const lvalue reference" when passed value from a function call
I expected this code to work, but it does not compile:
#include
struct S
{
int x = 0;
int y() const { return 1; }
};
bool f(const S& a, const S& b)
{
return std::tie(a.x, a.y()) < std::tie(b.x, b.y());
}
GCC 9 says:
error:…

John Zwinck
- 239,568
- 38
- 324
- 436
7
votes
2 answers
Does giving data an effective type count as a side-effect?
Suppose I have a chunk of dynamically allocated data:
void* allocate (size_t n)
{
void* foo = malloc(n);
...
return foo;
}
I wish to use the data pointed at by foo as a special type, type_t. But I want to do this later, and not during…

Lundin
- 195,001
- 40
- 254
- 396
7
votes
2 answers
Regarding lvalue-to-rvalue conversion, when is it required?
I've been reading quite many on the Internet and it seems that many people mentioned the following rules (but i couldn't find it in the standard),
The addition operator + (and all other binary operators) requires both operands to be rvalue, and the…

user534498
- 3,926
- 5
- 27
- 52
7
votes
1 answer
lvalue and rvalue for pre/postfix increment
Learning the lvalue and rvalue. The definition is whatever that can be "address of" is the left value and otherwise, it is rvalue.
I checked the operator precedence, both prefix and postfix increment has higher priority than the "address of"…

WriteBackCMO
- 629
- 2
- 9
- 18