I am starting to learn C and I am doing an assignment and this is part of the code I wrote:
if (2*b>9)
2*b = b (b0-b)/10;
I am getting error: expression is not assignable and terminal is pointing at the "=" sign. can you tell me what is wrong here. Sorry if stupid question . Thanks
CodePudding user response:
2*b
is an rvalue expression, so it can't be assigned. Instead you could assign the variable b
to equal half the expression on the right, as below:
if (2*b>9)
b = (b (b0-b)/10)/2;
CodePudding user response:
Assigning the expression 2 * b
is not possible (semantically it is not even clear what you might intend by that).
An assignment expression must be of the form: <lvalue> = <rvalue>
.
An lvalue is an expression that represents an object that occupies some identifiable location in memory (i.e. has an address), That is one of a simple variable, an array subscript reference or a dereferenced pointer.
Note that all lvalues are also valid rvalues.