In below code snippet, why line 2 + 3 = 5
statement gives error but next statement of assigning to string concatenation compiles successfully?
#include <string>
int main() {
2 + 3 = 5; // Error: lvalue required as left operand of assignment
std::string("2") + std::string("3") = std::string("5"); // Compiles successfully. why?
return 0;
}
My understanding is that left hand side of the expression std::string("2") + std::string("3") = std::string("5")
will produce temporary which is rvalue
. That means I am assigning to rvalue
- just like 2 + 3 = 5
. So it should also give lvalue required as left operand of assignment
error. But it does not.