lvalue required C/C++ Origin: Application & API OSI layer 7 · Application Last updated 28 Nov 2026

C/C++: error: lvalue required as left operand of assignment

You tried to assign to something that is not a modifiable variable, such as a literal, a function result or a comparison.

Exact message you may see lvalue required as left operand of assignmentexpression must be a modifiable lvaluelvalue required here
Seen on: C/C++ GCC Clang MSVC

Meaning

The classic cause is a typo like if (x + 1 = y) or a + b = c. Assignment needs a storage location on the left.

Common causes

  • = used instead of == in a condition
  • Assigning to a function return value
  • Assigning to a literal or expression
  • Assigning to a const object

⚡ Quick fix

  1. Use == for comparison
  2. Assign to a variable or reference
  3. Return a reference if you need to assign to the result

Detailed fix by platform

GCC / Clang

  1. Turn on -Wall -Wparentheses to catch = in conditions

Code examples

assignment instead of comparison

cpp
int a = 3, b = 5;
if (a + 1 = b) { }    // error: lvalue required as left operand of assignment
if (a + 1 == b) { }   // fine

How to diagnose

  1. Operator — Is it = or ==?
  2. Left — Is the left side a variable?
  3. Const — Is it const?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

cannot bind non-const lvalue reference — C++: error: cannot bind non-const lvalue reference of type 'T&' to an rvalue of type 'T' (C/C++)cannot bind non-const…case label does not reduce to an integer constant — C/C++: error: case label does not reduce to an integer constant (C/C++)case label does not r…conflicting types — C: error: conflicting types for 'foo' (C/C++)conflicting typesdiscards qualifiers — C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive] (C/C++)discards qualifiersexpected primary-expression before — C++: error: expected primary-expression before ')' token (C/C++)expected primary-expr…No CMAKE_CXX_COMPILER could be found — CMake Error: No CMAKE_CXX_COMPILER could be found (C/C++)No CMAKE_CXX_COMPILER…not a constant expression — C++: error: call to non-'constexpr' function / expression is not a constant expression (C/C++)not a constant expres…reference to is ambiguous — C++: error: reference to 'X' is ambiguous (using namespace std conflicts) (C/C++)reference to is ambig…lvalue re…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.