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
6
votes
2 answers
Overload resolution with rvalue reference to const char *
#include
using namespace std;
void f(const char * const &s) {
cout << "lvalue" << endl;
}
void f(const char * const &&s) {
cout << "rvalue" << endl;
}
int main()
{
char s[] = "abc";
f("abc");
…

alice
- 2,547
- 4
- 24
- 30
6
votes
1 answer
Why does `++a++` not compile in C++ but `(++a)++` does?
What the title says. For C++, (++a)++ does compile. Strangely enough, though, ++(a++) does not:
int main() {
int a = 0;
++a++; // does not compile
(++a)++; // does compile
++(a++); // does not compile
}
But in Java, it does not for…

Ryan Dougherty
- 528
- 6
- 21
6
votes
2 answers
Lvalues which do not designate objects in C++14
I'm using N3936 as a reference here (please correct this question if any of the C++14 text differs).
Under 3.10 Lvalues and rvalues we have:
Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue,…

M.M
- 138,810
- 21
- 208
- 365
6
votes
3 answers
C++ nonconst-const reference function overloading
In the following code:
int foo(const int& f) //version 1
{
int g = f;
return int(foo(g)); // calls itself, turning into SO
}
int& foo(int& f) //version 2
{
f *= -1;
return f;
}
int main()
{
int f = 11;
cout << foo(f) <<…

user1019710
- 321
- 5
- 14
6
votes
2 answers
Is it valid to bind non-const lvalue-references to rvalues in C++ 11?(modified)
I know in c++03, an an non-const reference cannot be bound to rvalues.
T& t = getT(); is invalid, and in c++11, we can do this: T&& t = getT(); but what about the above code, should that work in c++11?
I tested the codes below with vs11:
Foo…

Frahm
- 805
- 2
- 9
- 16
6
votes
6 answers
What is the reasoning behind the naming of "lvalue" and "rvalue"?
What is the reasoning behind the naming of "lvalue" and "rvalue" in C/C++?

Pioz
- 6,051
- 4
- 48
- 67
5
votes
1 answer
Why can't a++ (post-increment operator) be an Lvalue?
Code
#include
int main()
{
int a=3;
a++=5;
std::cout<

Abhishek Mane
- 619
- 7
- 20
5
votes
3 answers
Intitialzing an array in a C++ class and modifiable lvalue problem
I have a basic C++ class .The header looks like this:
#pragma once
class DataContainer
{
public:
DataContainer(void);
~DataContainer(void);
int* getAgeGroup(void);
int _ageGroupArray[5];
private:
int _ageIndex;
};
Now inside…

Michael IV
- 11,016
- 12
- 92
- 223
5
votes
1 answer
LValue ref qualified member function being called on an RValue object
I'm trying to figure out why the following snippet calls the LValue cast operator overload:
#include
class Foo
{
public:
Foo(int i = 0) : i(i) {}
operator const int& () const &
{
std::cout << "lvalue\n";
…

Christopher Leong
- 400
- 2
- 17
5
votes
2 answers
Confusion about an error: lvalue required as unary '&' operand
I have been trying to understand pointer concepts by writing simple code,
and I got an error problem, and it seems like I couldn't solve it or understand it.
#include
int *foo(void);
int main(void) {
printf("%d\n", *foo());
…

Ilwoong Choi
- 53
- 6
5
votes
1 answer
Should the member access operator of an rvalue be an xvalue?
In the cpprefernce section: Value categories, it states that "the member of object expression, where a is an rvalue and m is a non-static data member of non-reference type" is an xvalue. In the standard (I found in: N4140, the draft C++14 standard)…

Nathan Chappell
- 2,099
- 18
- 21
5
votes
3 answers
L Value required as increment operator - C
I just got a question from my Friend.
#include
void fun(int[][3]);
int main(void){
int a[3][3]={1,2,3,4,5,6,7,8,9};
fun(a);
printf("\n%u",a);
a++;//Ques 1
printf("\n%u",a);
printf("%d",a[2][1]-a[1][2]);
…

Arivarasan
- 285
- 1
- 7
5
votes
1 answer
Compiles as C++ but not C (error: lvalue required as unary '&' operand)
This line compiles when I use C++, but not C:
gmtime(&(*(time_t *)alloca(sizeof(time_t)) = time(NULL))); //make an lvalue with alloca
I'm surprised by this difference. There is not even a warning for C++.
When I specify gcc -x c, the message…

cshu
- 5,654
- 28
- 44
5
votes
2 answers
Binding r-value to l-value reference is non-standard Microsoft C++ extension
I've been working on a project recently, and I decided to install ReSharper C++ to Visual Studio. When it analysed my code it spat out a bunch of new warnings (apparently I have bad coding habits..). One of them that took me a while to figure out…

brads3290
- 1,926
- 1
- 14
- 20
5
votes
2 answers
Lvalue decaying to rvalue with auto error
I apologize if the question title is inaccurate - but I am having difficulties understanding what is going on here.
Consider the following class:
struct foo {
foo(foo&);
};
The following has no errors:
void func(foo& f) {
foo…

Robert Mason
- 3,949
- 3
- 31
- 44