raghu wrote:
#include<stdio.h>
int main(void)
{
int a=1;
int b=2;
int c=0;
c=(a+b)++;
printf("%d",c);
return 0;
}
For the above program I got the error as Lvalue required.I compiled in
Turbo C/C++ compiler.
Can anyone please explain why the error is and how to eliminate it .
In the expression `X++`, X must be a variable [1]. `a + b` isn't a
variable. The compiler correctly complains.
To eliminate this, don't do it. Decide what you mean and do that
instead.
[1] Technically, a "modifiable lvalue". Historically, the term
"lvalue" meant "the /value/ you get when you evaluate an
expression on the /l/eft of a [traditional] assignment".
Expressions like `x + y` don't have lvalues in C (they do
in some other languages -- no modern ones that I know of,
though, not that that means much. "Next 700 programming
languages, ha, 700 is a *wimp*.).
C's lvalue means something like "an expression that
could designate an object". Which means a non-const
variable or `*E` (and hence `A[i]` for fitting `A`
and `i`) where E's type is pointer-to-nonconst-object-
type-and-that-excludes-void-and-it-mustnot-be-null-either.
I'm sure there's something I've forgotten but that should
get you started.
--
Chris "hantwig efferko VOOM!" Dollin
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/