-4

I am trying to get the value for the last equation

int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0;

a = b++ + ++c;
printf("a=%d\n", a);

x = y + 1 + ++z;
printf("x=%d\t", x);

printf("b=%d\t", --b);
printf("b=%d\t", b++);
printf("c=%d\t", c+1);
printf("c=%d\t", 2-c);

whats the value of the last equation and why? how do I calculate it

Wenhan Xiao
  • 194
  • 1
  • 11

1 Answers1

3

These statements

printf("c=%d\t", c+1);
printf("c=%d\t", 2-c);

do not change the value of the variable c.

The variable was changed only in this statement

a = b++ + ++c;
          ^^^

If you want to change the variable c in the calls of printf then you should write at least

printf("c=%d\t", c = c+1);
printf("c=%d\t", c = 2-c);

Then the output will look like

a=1
x=2 b=0 b=0 c=2 c=0
                ^^^

Without these changes the output is

a=1
x=2 b=0 b=0 c=2 c=1 
                ^^^  
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335