cout<<(x++)++; //fails 
cout<<++(++x); //passes
Why does the post increment fail ? I see it happen but not sure of the technical reason.
cout<<(x++)++; //fails 
cout<<++(++x); //passes
Why does the post increment fail ? I see it happen but not sure of the technical reason.
 
    
     
    
    x++ returns an rvalue so you can't perform ++ again on it. On the other hand, ++x returns an lvalue so you can perform ++ on it.
 
    
    This is how the increment operators work in C/C++.
If you put the ++ after the variable (postfix increment), the whole expression evaluates to the value of the variable before incrementing.
If you put the ++ before the variable (prefix increment), the expression evaluates to the value after the increment operation.
While the prefix operation returns a reference to the passed variable, the postfix version returns a temporary value, which must not be incremented.
