lvalue error needs explanation

A

Akhil

plz c d following code

#include<stdio.h>
void main()
{
int x=4,y=1;

y=x++++; //gives error message lvalue required

y=x++ + ++y;//no errors

y=x+++++y ;//lvalue required

y=(++x)++; //no errors
}

explanation needed for the all four statements nd a bit bout lvalues.

program tested on turbo 4.5 32 bit compiler.
 
C

Chris Dollin

Akhil said:
plz c d following code

Syntax error: non-word "plz".
Syntax error: unexpected initial "c".
Syntax error: unexpected initial "d".
Syntax error: imperative must end with "." or "!".
Warning: April is the cruelest month.
#include<stdio.h>
void main()

non-int `main`s produce undefined behaviour.
{
int x=4,y=1;

y=x++++; //gives error message lvalue required

An "lvalue" is (roughly) an addressable object, a variable.
The left operand of ++ must be a lvalue. The result of ++
is a number. Numbers are not lvalues. QED.
program tested on turbo 4.5 32 bit compiler.

If it were a program, it would have compiled.
 
A

Akhil

thnx for d reply but i still hav a problem ....

if we exeucte the statement y=(++x)++; then thr is no error ++x will
again b a number nd left operand of ++ shud b a lvalue so y does it
work in this case.
 
C

CBFalconer

Akhil said:
plz c d following code

Gobble-de-gook is not understandable.
#include<stdio.h>
void main()

main returns int. All bets are off.
{
int x=4,y=1;

y=x++++; //gives error message lvalue required

Syntax errors normally do that.

.... snip ...
program tested on turbo 4.5 32 bit compiler.

No non-compilable program is tested.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
C

Chris Dollin

Akhil said:
thnx for d reply but i still hav a problem ....

Yes, you're still writing in gobbledegook. Please use English words
and English grammar.
if we exeucte the statement y=(++x)++; then thr is no error

Yes, there is - "invalid lvalue in increment" is how my local gcc reported
it.
++x will
again b a number nd left operand of ++ shud b a lvalue so y does it
work in this case.

Broken compiler - /if/ it really did work.
 
I

Ian Collins

Akhil said:
plz c d following code

#include<stdio.h>
void main()
{
int x=4,y=1;

y=x++++; //gives error message lvalue required
You can't modify the result of x++, so it can't be an lvalue (something
that appears on the left hand side of an expression).
 
I

Ian Collins

Ian said:
You can't modify the result of x++, so it can't be an lvalue (something
that appears on the left hand side of an expression).
Sorry, that came out wrong, I should have said you can't modify the
expression x++.
 
J

Jordan Abel

plz c d following code

#include<stdio.h>
void main()
{
int x=4,y=1;

y=x++++; //gives error message lvalue required

x++ returns a value, which you are then trying to increment
y=x++ + ++y;//no errors

Except, of course, the undefined behavior
y=x+++++y ;//lvalue required

this parses as x++ ++ +y
y=(++x)++; //no errors

It _should_ be the same error as x++++ - i can't imagine why it's not.
Have you actually tried this, or did your teacher just _say_ there are
no errors?
explanation needed for the all four statements nd a bit bout lvalues.

lvalues are, basically, expressions that it is legal to assign to /
modify / increment - say, the name of a variable.
 
J

Jordan Abel

thnx for d reply but i still hav a problem ....

if we exeucte the statement y=(++x)++; then thr is no error ++x will
again b a number nd left operand of ++ shud b a lvalue so y does it
work in this case.

Your compiler failed to provide a required diagnostic, and is thus not a
conforming ANSI C implementation.
 
V

Vladimir S. Oka

Jordan said:
It _should_ be the same error as x++++ - i can't imagine why it's not.
Have you actually tried this, or did your teacher just _say_ there are
no errors?

It certainly produces the same `lvalue` error on GCC 3.4.2
(mingw-special) when compiled with paranoid options.

Don't have this to test OP's results, but I have a strogn suspicion
that OP did not in fact try to compile this. If it does really compile
on TC 4.5, I'd complain to the vendor, but that won't work, as it's
discontinued.
 
A

Akhil

Akhil said:
plz c d following code

#include<stdio.h>
void main()
{
int x=4,y=1;

y=x++++; //gives error message lvalue required

y=x++ + ++y;//no errors

y=x+++++y ;//lvalue required

y=(++x)++; //no errors

i hav checked it on two compilers now the other one is DevC++ ,you can
find full specfication at
(http://csjava.occ.cccd.edu/~gilberts/devcpp5/) it certainly works in
both cases but might be because its primarily a c++ compiler anyways
please comment.
 
A

Akhil

sorry it was my fault actually i was compling the file with .cpp
extension so it was compiled as a c++ source code and hence no errors,i
got the error when i compiled the source code with .c extension,no more
questions
 
K

Keith Thompson

Akhil said:
sorry it was my fault actually i was compling the file with .cpp
extension so it was compiled as a c++ source code and hence no errors,i
got the error when i compiled the source code with .c extension,no more
questions

Yes, C and C++ are different languages with different rules.

Thank you for dropping the silly abbreviations. You can help us even
more by using standard capitalization (the first word of each sentence
and the word "I"), and by following each comma with a blank.

I see you've read <http://cfaj.freeshell.org/google/>; please *always*
provide context when you post a followup, even if you're following up
to yourself.
 
C

Christian Bau

"Akhil said:
plz c d following code

#include<stdio.h>
void main()
{
int x=4,y=1;

y=x++++; //gives error message lvalue required

y=x++ + ++y;//no errors

y=x+++++y ;//lvalue required

y=(++x)++; //no errors
}

explanation needed for the all four statements nd a bit bout lvalues.

program tested on turbo 4.5 32 bit compiler.

Just write down exactly what tokens the compiler sees; that will make it
obvious why spaces make a difference. A compiler is likely to give a
message "lvalue required" if an lvalue is required as an operand and the
operand you used is not an lvalue. So write down which operands are
lvalues and which are not.

For additional homework points: Spot the very serious error in "y=x++ +
++y;" which you say has no error. Then tell us what the error is in
"y=(++x)++;" which you say has no error. Then tell us which is the very
first error in that program.
 
C

Christian Bau

"Akhil said:
thnx for d reply but i still hav a problem ....

if we exeucte the statement y=(++x)++; then thr is no error ++x will
again b a number nd left operand of ++ shud b a lvalue so y does it
work in this case.

For heavens sake, use English.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top