Addresses and pointers
Line 3 makes an int called x. It needs 4 bytes of memory. Memory is a long row of bytes, and each byte has a number: its address. x starts at 0x1000, and holds 5.
Line 4: &x means the address of x, here 0x1000. It is stored in a new variable, p. A variable that holds an address is a pointer. We say p points to x, and draw an arrow.
p is a variable like any other: it has its own address, 0x1008, and its own size, 8 bytes on a 64-bit machine. Its type, int*, says that what it points to is an int.
Using a pointer
The * in front of p means: follow the address in p. So *p = 8 goes to 0x1000 and writes 8 there. That is x's memory, so x is now 8, though line 5 never names x.
Line 6 prints x, and the terminal shows 8, not 5. The write went through the pointer into x's own memory. Two names, x and *p, reach the same 4 bytes.
Line 7 makes y at 0x1004. Line 8, p = &y, has no star: it changes p itself. p now holds 0x1004, so the arrow swings to y. x keeps its 8.
Line 9 prints *p. The program reads p, gets 0x1004, follows it to y and reads the 7 stored there. The same code, *p, now means y.
Null pointers
Line 10 sets p to nullptr, the null pointer: a value that means points at nothing. The arrow is gone. p still exists and still takes 8 bytes; it just has no target.
Writing *p now would follow a pointer that points nowhere. That is undefined behaviour: C++ promises nothing, and the program usually crashes. So check first: if (p) runs its code only when p points somewhere.
What happens
;; step 1/9 · address 3 int x = 5; x an int: 4 bytes on this machine where at address 0x1000 (bytes 0x1000 to 0x1003) value 5 addresses here are made up and short; real ones are longer, like 0x16fdff0bc, and change from run to run
The addresses on the figure are made up and short so they fit. Real addresses are longer (on a 64-bit machine, something like 0x16fdff0bc), and most systems place a program at a different address every run. The compiler, not you, decides where x, y and p go and in what order; they may not sit side by side. Sizes depend on the platform. The C++ standard only says int is at least 16 bits. On today's usual 64-bit systems (Linux, macOS, Windows) an int is 4 bytes and a pointer is 8; check with sizeof(int) and sizeof(int*).