Increment operator inside array

Loki San Hitleson picture Loki San Hitleson · Dec 13, 2015 · Viewed 17.1k times · Source

I have a C program which does queue operations using an array. In that program, they increment a variable inside array. I can't understand how that works. So, please explain these operations:

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

Answer

LogicStuff picture LogicStuff · Dec 13, 2015

Please explain these operations.

  1. array[++i]; - first increments i, then gives you element at the incremented index

    equivalent to:

    ++i; // or i++
    array[i];
    
  2. array[i++]; - also first increments i, but postfix operator++ returns i's value before the incrementation

    equivalent to:

    array[i];
    ++i; // or i++
    

They increment a variable inside array.

No, they don't. You could say they increment i within the call to array subscript operator.