Step 6 of 6
Tracing values
= copies a value into a variable, once. After a = b;, the variable a holds the same number as b, but the two aren't linked: changing b later doesn't change a.
int b = 5;
int a = b;
b = 8;
System.out.println(a);
System.out.println(b);
5
8When a program gets confusing, trace it by hand: go through it line by line and write down what each variable holds after each line.
| After line | a | b |
|---|---|---|
int b = 5; |
5 | |
int a = b; |
5 | 5 |
b = 8; |
5 | 8 |
Tracing is how programmers check their own thinking, and it's a skill worth practicing on paper, without running anything.