L value reruired

Status
Not open for further replies.

Virus Guy

Broken In
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.
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
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...
 
OP
V

Virus Guy

Broken In
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
 

Zangetsu

I am the master of my Fate.
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 Bottom