In
a[index++]=num;
a
is first indexed by
index
, that cell is set to
num
, and finally
index
is incremented.
In
a[++index]=num;
index
is first incremented and
then used as the index for the cell that is set to
num
.
This means that your first assignment is actually
a[-1]=num;
after which
a[0]
still contains random junk:
-606760192
in this case. Not only that, but assigning to
a[-1]
will usually corrupt memory or cause your program to immediately crash in a debug build that includes array bounds checking.