I tried this example of array and post increment/ pre increment on it's elements
#include<stdio.h>
int main()
{
int j[5] = {5, 1, 15, 20, 25};
int k , l, m, n;
n = ++j[1];
k = ++j[1];
l = j[1]++;
m = j[k++];
printf("\n%d, %d, %d, %d", n, k, l, m );
return 0;
}
here the output is :
2, 4, 3, 20
and if i change the order of n and k ie instead of
n = ++j[1];
k = ++j[1];
i write
k = ++j[1];
n = ++j[1];
The output becomes :
3, 3, 3, 15
I tried this on mingw compiler on windows10 and also on Kali Linux's GCC... Same problem.
It is just like taking different variable name alters the output of program. What might be the cause?
Thanks Everyone for helping me out with this question.
I didnt take the last post increment of k under consideration.
The results would be same of i would have changed
m=j[k++]
with
m = j[n++]