Here, **q and *p are changing the value stored in them, not the addresses.
I think the person who has created the program, has only created it for understanding pointers, not for spreading message that you can only access pointers using pointers. Actually you don't access pointers by pointers, they can be accessed like any other variable, but must not be done like that (unless you know that the memory address you're accessing is accessible by your program) because the addresses are given by the OS, and writing to an address not provided to your program will cause undefined behavour.
To understand pointers, you can read this porgram (the explanation is given at the end)-
#include <stdio.h>
int main() {
int a = 300; // define variable 'a' with value 300
int *p = &a; // define pointer 'p' and assign it the address of 'a'
int b = *p; /* define variable 'b'. Note that now 'p' contains some address,
which is the address of variable 'a'. Since now you're 'dereferencing' the
value of 'p', which is an address, you'll have the value of 'b' to be equal
to value of 'a'*/
int **pp = &p; /* here we give the address of pointer 'p' to pointer
to pointer 'pp'*/
printf("a: %d\n", a); // print value of 'a'
printf("*p: %d\n", *p); // print value of '*p' (which is equal to value of 'a')
printf("p: %p\n", p); // this will print value of 'p' (which is address of 'a')
printf("**pp: %d\n", **p); // this will print value of '**pp' (equal to 'a')
printf("b: %d\n", b); // print value of 'b'
return 0;
}
Pointers and pointers to pointers can be thought about like this (they in reality are like this)-
Variable a has value 300, and has an address in the memory, which is assigned by the OS.
Pointer p is defined equal to the address of variable a. It also has its own address in memory.
Variable b is defined equal to the value of the memory at a location. The location is given by value of p (which is address of variable a). It has its own address in memory.
Pointer to pointer pp is defined to be equal to address of pointer p. It also has its own address in the memory.