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.
lvalue required as left operand of assignmentexpression must be a modifiable lvaluelvalue required here 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
- Use
==for comparison - Assign to a variable or reference
- Return a reference if you need to assign to the result
Detailed fix by platform
GCC / Clang
- Turn on
-Wall -Wparenthesesto catch=in conditions
Code examples
assignment instead of comparison
int a = 3, b = 5;
if (a + 1 = b) { } // error: lvalue required as left operand of assignment
if (a + 1 == b) { } // fineHow to diagnose
- Operator — Is it = or ==?
- Left — Is the left side a variable?
- 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:
Similar errors
Most viewed in C/C++
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- Bus error C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 28 Nov 2026