-1

If

void main()
{ 
  int i=2,j=4; 
  i=+++i+j; //is not an error 
  i=---i+j; // is a L-value required error..
}

could anyone please explain in detail the concept behind multiple increments and decrements..

Paul Richter
  • 10,908
  • 10
  • 52
  • 85
john fedric
  • 167
  • 1
  • 11

1 Answers1

0

I think the parser is not able to parse it in the format it wants it to be. Try using parenthesis as below. It would work.

i=-(--i)+j;

Saurabh
  • 1,086
  • 1
  • 15
  • 27
  • The question is what's different about the `-` operator and the `+` operator that the first one works. – woolstar Jan 21 '14 at 18:39
  • exactly sir..could you please explain me why first one works.. – john fedric Jan 21 '14 at 18:43
  • In both cases the program exhibits undefined behaviour and the output could be anything. 1. main should return int not void. In C returning void is an extension that not all compilers support making the code non-portable, in C++ it is just undefined behaviour. 2. both cases break the part of the standard that specifies variable may not be accessed more than once between sequence points where at least one of those accesses is to alter the variables value. The standard states that in such a case the behaviour will be undefined. I suggest you look sequence points and undefined behaviour on web. – Saurabh Jan 21 '14 at 20:35