Q:

Difference between b=b++ and b++

I was asked in an interview the below question.
int b = 0;
b = b++;
b = b++;
b = b++;
b = b++;

what will be the value of b after every line execution ?
The output is coming as 0 for every line.
Why is the output not coming as 0,1,2,3 ?

A:

In Java, the expression
b = b++

is equivalent to
int tmp = b;
b = b + 1;
b = tmp;

Hence the result.
(In some other languages, the exact same expression has unspecified behaviour. See Undefined behavior and sequence points.)

A:

Hint:
int b = 0, c;
c = b++;
c = b++;
c = b++;
c = b++;
System.out.println(c);

c now will be 3 like you thought, but because in your question you're assigning b, it'll get 0, because as already explained, it's the same as:
int tmp = b;
b = b + 1;
b = tmp;

