0
#include<stdio.h>
int main(void)
{
    int a[5]={100, 1, 0, 200, 1};
    int i = 2, j, m;
    m = a[i++]++ + ++a[++i];
    printf("\n m = %d \n", m);
    return 0;
}

Upon running the code using GCC, the value of 'm' obtained is 2. When the given formulae for m is split into 2 parts as (a[i++]++) and (++a[++i]), the results obtained are 0 and 201 respectively. I'm unable to understand the logic here, kindly help. Thank you!

  • 1
    This comes up SOOO often that I just wish it would be a compiler error. I'd love to see the compiler refuse to compile code like this, rather than leave junior programmers to question the result. – abelenky Nov 15 '22 at 19:47

0 Answers0