1

I had written a program in C to print different values of a

This is the code:

int main(void)
{
    int a = 10;
    printf("%d %d %d %d", a++, ++a, a--, --a);
    return 0;
}

The output is:

9 10 9 10

But how the output is decided to print like this?

Also how the output will be decided for x, if I use them in the expression as : int x = ++a + ++a; or int x = a++ - --a + a--; or something like this.

Is it something to do with the precedence order or something different is there? Please explain this to me that how the output of these two things are decided?

  • 1
    similar questions asked a bazillion times.... – Mitch Wheat Dec 30 '20 at 10:20
  • That is possibly because the code is to be found in the book **"Let us C" by Yashwant Kanetkar** and has caused untold hours of wasted time. The output of the code is undefined. Please also see [sequence points in c](https://stackoverflow.com/questions/3575350/sequence-points-in-c). – Weather Vane Dec 30 '20 at 10:55

0 Answers0