I try to define mathematical operations in geany but it fails to compile them. For example, a+b=c can't get compiled, but on the other hand a+b==c gets compiled but the result of lets say 2+4 is 0 so it is not right. same goes for a-b=d and other basic operations. When i tried to compile this in terminal the same error was there saying "lvalue required as left operand of assignment". I'm using linux, openSUSE to be more precise.
Asked
Active
Viewed 969 times
-2
-
Your question is not clear. What is the code you're trying to compile ? – Aleph0 Mar 27 '15 at 12:28
-
== means compare if right and left is equal and will return true/false or 0/1 depending on language. you assign from right to left in programming meaning that you ned to say a = b+c and not a+b=c – Thomas Andreè Wang Mar 27 '15 at 12:29
-
a= b+c works, thanks! – shonjo Mar 27 '15 at 13:18
2 Answers
0
Since you want to assign, you need to do it like:
c = a + b;
==
is comparison operator. It compares a+b
with c
.
For example:
int a = 5;
int b = 5;
int c = 10;
if (a+b == c) <---true because 10 = 10
{
//some code
}
Here is a good source to understand about lvalue and rvalue:
http://eli.thegreenplace.net/2011/12/15/understanding-lvalues-and-rvalues-in-c-and-c

sam
- 2,033
- 2
- 10
- 13
0
In a simple description ... an LValue is a variable to which you can assign a value to. So in your case, you want to assign the value of the addition of a+b to the variable c:
c = a + b;
With this operator==() you compare 2 values with each other. Back to your case you compare the addition of a+b with the value of c. And if "a+b" is not equal to "c", this comparison returns "false". "false" casted to a numerical datatype like int would have the value of 0.

Mr.Yellow
- 197
- 1
- 8