Expressions and Assignment Statements

AP Computer Science A· difficulty 3/5

int a = 5;
int b = a++;

Which set of statements gives the same final values of a and b?

  • A

    int a = 5; int b = a; a = a + 1;

    check_circle
  • B

    int a = 5; a = a + 1; int b = a;

  • C

    int a = 5; int b = a + 1;

  • D

    int a = 6; int b = 6;

Explanation

Postfix a++ assigns the original value (5) to b first, then increments a to 6. Option A reproduces this exactly.

Want 10 more like this — adaptive to your weak spots?

Related questions