Lvalue Required......Why?

S

Sai Krishna M

Lvalue Required......Why?


Hello all,

the following code is not compiling in Turbo C and the error
is "Lvalue Required" .

main()
{

int i;

i++ = 10;

}


As I understand, we're trying to assingn 10 to i first, gettin 11 and then
trying to increment 11, which doesn't have a memory loc, being a Number.

But, why also 11 should ha a location, right?



plz clarify.
 
C

Chris Dollin

Sai said:
Lvalue Required......Why?

It's the Law.
the following code is not compiling in Turbo C and the error
is "Lvalue Required" .

main()
{
int i;
i++ = 10;

The result of i++ is a value, not an assignable object. You can't assign
to values: `10 = 17;` is not legal.

[Note also that i++ is Bad anyway, since i is not initialised.]
}

As I understand, we're trying to assingn 10 to i first, gettin 11 and then
trying to increment 11, which doesn't have a memory loc, being a Number.

No - we're "trying" to assign 10 to the result of i++. The i++ must be
evaluated before the assignment happens. [Well, it would be "must" if
it were legal, if it were legal and sane.]
But, why also 11 should ha a location, right?

Wrong.
 
J

John Bode

Sai Krishna M said:
Lvalue Required......Why?


Hello all,

the following code is not compiling in Turbo C and the error
is "Lvalue Required" .

main()
{

int i;

i++ = 10;

The result of the autoincrement operator on an int object is a value,
and you cannot assign to a value (what you have written is basically
the equivalent of writing 0 = 10, except there's no guarantee that i
was initialized to 0). i++ reads as "return the current value of i,
then at some point before the next sequence point, increment i by 1."
}


As I understand, we're trying to assingn 10 to i first, gettin 11 and then
trying to increment 11, which doesn't have a memory loc, being a Number.

But, why also 11 should ha a location, right?

Not necessarily. If I have the lines

i = 10;
i++;

the line "i++" evaluates to 10, which is then discarded.
 
P

Peter Shaggy Haywood

Groovy hepcat Sai Krishna M was jivin' on Thu, 20 Nov 2003 14:58:27
+0530 in comp.lang.c.
Lvalue Required......Why?'s a cool scene! Dig it!
the following code is not compiling in Turbo C and the error
is "Lvalue Required" .

i++ = 10;

As I understand, we're trying to assingn 10 to i first, gettin 11 and then
trying to increment 11, which doesn't have a memory loc, being a Number.

But, why also 11 should ha a location, right?

Wrong!
plz clarify.

Go and get FAQed. You should have read the FAQ before posting. Go
and do so right now. You'll find the FAQ at the following URL:

http://www.eskimo.com/~scs/C-faq/top.html

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
P

Peace

Sai Krishna M said:
Lvalue Required......Why?

Read the FAQ it's the LAW.
Hello all,

the following code is not compiling in Turbo C and the error
is "Lvalue Required" .

main()
{

int i;

i++ = 10;

}
What are you trying to achieve here? i++ is evaluates to a value, it
is not a variable to which you can assign a value.Why can't you write
your peice of code like this:
void main ()
{
int i=9;
i++;
}
As I understand, we're trying to assingn 10 to i first, gettin 11 and then
trying to increment 11, which doesn't have a memory loc, being a Number.
Wrong. Go read some good C books.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top