-2

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.

shonjo
  • 1

2 Answers2

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