what is ++a[b++]*a[2]+++--a[3]; and why | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

20th Apr 2019, 2:19 PM
Mario S
2 Answers
+ 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.
20th Apr 2019, 3:48 PM
Shadow
Shadow - avatar
- 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...!!!
20th Apr 2019, 3:27 PM
Kuri
Kuri - avatar