L value reruired

Status
Not open for further replies.

Virus Guy

Broken In
Joined
May 3, 2008
Messages
42
Friends i am getting an ERROR : L value required for the below program at line no :3.

void main(){
int x=5;
++x++;
printf("X = %d ",x);
}

Can any one please explain me the concept of L value.
 

Sykora

I see right through you.
Joined
Sep 10, 2005
Messages
594
What are you trying to do? ++x++ is invalid. You can only apply one of them at a time.

An lvalue is anything that can come on the left side of an '=' sign. When you use x++, it is interpreted as 'x = x + 1'. Here, x is an lvalue.

When you use ++x++, it tries '++x = x + 1', but ++x is not an lvalue, hence the error.
 

furious_gamer

Excessive happiness
Joined
Jun 17, 2008
Messages
4,246
lol..... ++x++... Will u plz explain me whats the logic behind this....
And yes as the above member said LValue means the value in the left side.... So change ur code by break up ur logic as ++x,x++ so...
 

n2casey

Super Hero - Super Powers
Joined
Sep 1, 2006
Messages
764
lol..... ++x++... Will u plz explain me whats the logic behind this....
And yes as the above member said LValue means the value in the left side.... So change ur code by break up ur logic as ++x,x++ so...

++x++ lol
postfix x++
prefix ++xx

There is no point for lol, may b he has just started learning C...
 
OP
V

Virus Guy

Broken In
Joined
May 3, 2008
Messages
42
What are you trying to do? ++x++ is invalid. You can only apply one of them at a time.

An lvalue is anything that can come on the left side of an '=' sign. When you use x++, it is interpreted as 'x = x + 1'. Here, x is an lvalue.

When you use ++x++, it tries '++x = x + 1', but ++x is not an lvalue, hence the error.

why ++x is not an lvalue can you please tell me clearly
 

QwertyManiac

Commander in Chief
Joined
Jul 17, 2005
Messages
6,575
I suppose that the lvalue requires itself to be an object/variable, and not a statement/expression.
 

Zangetsu

I am the master of my Fate.
Joined
Jan 8, 2008
Messages
12,332
Friends i am getting an ERROR : L value required for the below program at line no :3.

void main(){
int x=5;
++x++;
printf("X = %d ",x);
}

Can any one please explain me the concept of L value.

I think u wanna increment it 2 times i.e 1st pre-increment & then post increment...
ur syntax is wrong dats y u got lvalue required error...
use
++x;
x++;
instead of ++x++;

the compiler reads from left 2 right..so on 3rd line it first sees ur + sign & again
+ sign & then x so it thinks its a preincrement operation..but it also
sees other 2 + sign gets confused & coz the ++x results in a value 2 processing
error is there ....& 4 remaing 2 plus signs it needs a value 2 store them
hence the error
 
Status
Not open for further replies.
Top