0

The following C code executes correctly but not as expected. Post increment operator here in z=z++ is creating confusion here. I may not be able to figure out silly mistake/concept, Can I have a brief explanation or some helpful link please.

 #include<stdio.h>
    int main()
    {
        int x=5,y=6,z=7;
        if(x-y)

            z=z++;
            z=--z;

        printf("%d",z);
    }
skyconfusion
  • 123
  • 8

1 Answers1

0

You are not allowed to do z=z++; because between 2 sequence points you are not allowed to assign a variable 2 times.

This one is a full expression in which you assign z 2 times. So it can be interpreted ambigously and the result of the C abstract machine is undefined behavior.

The same for z=--z.

alinsoar
  • 15,386
  • 4
  • 57
  • 74