0

hello,
in the following question
c=4;
d= (++c)++; //It works in gcc compiler
d= (c++)++; //it didn't work
what i have read that ++c or c++ returns a value which can't be again incremented or decremented (like 5++).
i want to know how the first statement works and second statement do not?
please help me in this question.........

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by siddhant3s
0

Prefix increment/decrement operators return lvalue (a reference to operator argument in C++ terms) so it's possible to increment/decrement this lvalue. Postfix increment/decrement operators return rvalue (a value as is, not a reference to) so it's impossible to increment this value (it's not a variable).

0

what i have read that ++c or c++ returns a value which can't be again incremented or decremented (like 5++).
.

You have read wrong.
You are though right by saying both of these operator returns a vale, but the pre-fix(++x) return that value by reference. That means it can be on the left side of assignment operator.

//although the code is meaningless but then too..........
int i=1,y=0;
i++++;
cout<<i;

Search what do Return by reference means

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.