0
what is ++a[b++]*a[2]+++--a[3]; and why
int main () { int a [6] = {1,2,3,4,5,6}; int b = 1; int x; ++a[b++]*a[2]+++--a[3]; } i know it will be 12, but can someone explain some details?
2 ответов
+ 3
Nagendra, I think your interpretation is not entirely correct, because
++a != a[1]
Rather ++a[b++] increments the value stored at a[b], which would be ++2 = 3.
Afterwards it is multiplied by a[2]++, which is an post-incrementation of the value stored at a[2], which is 3. Since it is incremented afterwards, it remains 3, therefore 3*3 = 9.
For the last part, the value at a[3] is decremented, thus --4 = 3, and then added to 9, making the result 12.
- 1
See my interpretation -
++a=a[1]
b++ = Post increment. Value of b will be taken before increment.
++a[b++] =a[1 +1]= a[2] =3;
++--a[3]= a[3]=4;
++a[b++]+++--a[3] can be e interred based on operator preedance as - (++a[b++]) +(++--a[3]) = 3*4 = 12
Hope this helps...!!!