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

**Code:** `lvalue required` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang, MSVC

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/lvalue-required-as-left-operand)
