Why it is that the left hand side of assignment operator must have a variable?

It so because only a variable can have operation performed in it. To explain this concept more briefly let us see an example.

Consider the following program:



int a=10;

int b;




int c;




The above program will not work and would give a error message as LValue Required.

This is because of the statement sample(++a++).

In ++a++ the ++a gets operated first resulting in a=a+1 = 10+1=11

Now 11++ gives error because one cannot increment constants and can perform such operations only on variables. In other words the operation 11++ would be expanded as 11= 11+1 which is not true and so cannot be done. And so the above program gives error as variable or lvalue required.

So it is essential that on the left hand side of the assignment operator a variable in other words an lvalue must occur.

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 1 of 1 Answers

for any constant value we can't assign the value.So. We can assign the value for only variable. SO. that only the leftside should be vaiable.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions