int main(){ int x<3>=4,5,6; int *p=x; ns +1=p;/*compiler shows error speak lvalue compelled as left operand that assignment*/ cout


When you have actually an assignment operator in a statement, the LHS that the operator must be miscellaneous the language call an lvalue. If the LHS of the operator does no evaluate come an lvalue, the value from the RHS can not be assigned come the LHS.

You are watching: Lvalue required as left operand of assignment c++

You cannot use:

10 = 20;since 10 does no evaluate come an lvalue.

You can use:

int i;i = 20;since ns does advice to an lvalue.

You can not use:

int i;i + 1 = 20;since ns + 1 does no evaluate come an lvalue.

In her case, ns + 1 does no evaluate come an lavalue. Hence, you can not use

p + 1 = p;
answered Oct 27 "15 in ~ 18:01


R SahuR Sahu
199k1313 gold badges140140 silver- badges255255 bronze title
include a comment |
To assign, you need to use p=p+1; instead of p+1=p;

int main(){ int x<3>=4,5,6; int *p=x; p=p+1; /*You just needed to switch the state around*/ cout
reply Oct 27 "15 in ~ 17:53


25.4k1515 yellow badges5959 silver- badges7979 bronze badges
include a comment |
Put simply, one lvalue is something the can show up on the left-hand side of one assignment, commonly a change or selection element.

So if you specify int *p, then p is one lvalue. P+1, i m sorry is a valid expression, is not an lvalue.

If you"re do the efforts to include 1 to p, the exactly syntax is:

p = p + 1;
answer Oct 27 "15 in ~ 18:02


178k1818 yellow badges183183 silver- badges229229 bronze title
include a comment |
if you usage an assignment operator yet use it in wrong method or in wrong place, then you"ll get this types of errors!

suppose if you type:p+1=p; girlfriend will gain the error!!

you will get the same error for this:if(ch>="a" && ch="z")as you see can see that ns i make the efforts to entrust in if() statement!!!how silly i am!!! right??ha haactually ns forgot to give less then( if(ch>="a" && chand got the error!!

answered Oct 24 "17 in ~ 13:46
1111 bronze badge
include a comment |
It is simply a typo(I guess)-

p+=1;instead of p +1=p; is required .

As name suggest lvalue expression should be left-hand operand the the assignment operator.

answer Oct 27 "15 at 17:58
16.1k22 gold badges2323 silver badges4040 bronze title
include a comment |

her Answer

Thanks because that contributing an answer to ridge Overflow!

Please be sure to answer the question. Carry out details and also share her research!

But avoid

Asking because that help, clarification, or responding to various other answers.Making statements based on opinion; ago them up with referrals or personal experience.

To discover more, view our advice on writing good answers.

See more: Microsoft Visual C# How To Program 6Th Edition, The Latest Supported Visual C++ Downloads

Draft saved
Draft discarded

Sign up or log in in

sign up making use of Google
authorize up using Facebook
authorize up making use of Email and Password

Post together a guest

email Required, yet never shown

Post as a guest


Required, but never shown

post Your price Discard

By clicking “Post her Answer”, friend agree come our terms of service, privacy policy and cookie policy

Not the prize you're spring for? Browse other questions tagged c++ pointers forced lvalue or questioning your very own question.

The Overflow Blog
Featured ~ above Meta
Visit chat
2 different weird errors v struct assignment
objective C - Lvalue required as left operand of assignment
GCC error once compiling: "lvalue required as left operand of assignment" with duty pointer
Overloading operator<> and NOT obtaining "lvalue forced as left operand that assignment" error
"lvalue forced as left operand of assignment" when using pointers in C
warm Network concerns more hot inquiries

question feed
i ordered it to RSS
question feed To i ordered it to this RSS feed, copy and paste this URL right into your RSS reader.

stack Overflow
stack Exchange Network
site design / logo © 2022 ridge Exchange Inc; user contributions licensed under cc by-sa. Rev2022.1.12.41154

Stack Overflow works best with JavaScript permitted

your privacy

By click “Accept all cookies”, you agree stack Exchange deserve to store cookie on your machine and disclose info in accordance v our Cookie Policy.