-1

If I had a variable i with a value of 0, would the statement:

array[i] = array[++i];

be the same as

1 : array[0] = array[1];

or

2 : array[1] = array[1];?

Sorry if it's a dumb question.

hansoko
  • 155
  • 9
  • `++a` is the same as `a += 1`, `a++` is the value of `a` before incrementing. – binaryescape Aug 04 '23 at 12:55
  • 8
    Don't write code like this. Ever. – Jabberwocky Aug 04 '23 at 12:56
  • 1
    Neither (1) nor (2), because the behavior of the statement in question is *undefined*. – John Bollinger Aug 04 '23 at 13:14
  • It's not a dumb question, it's an important one. As everyone is pointing out here, just **don't** do this. Not only is it wildly ambiguous, it's not properly defined in the standard, meaning the behaviour is unpredictable and this code is in actuality a bug. – tadman Aug 04 '23 at 14:33

0 Answers0