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:
main()
{
int a=10;
int b;
b=sample(++a++);
}
sample(c)
int c;
{
printf(“%d”,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.
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:
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.
Profile Answers by GeekAdmin Questions by GeekAdmin
Questions by GeekAdmin answers by GeekAdmin
Related Answered Questions
Related Open Questions