First of all, before going into the details of pointer , the Memory access provided by C language is dangerous to use in this way. usually you don't define the addresses of the locations you want to save variable at or the address of the pointer itself as you mentioned in the code.
#include <stdio.h>
int main() {
int v = **0x3002**;
int* p = **0x3000;**
p = &v;
(*p)++;
printf("v = %x\n", v);
printf("%x\n", p);
printf("*p = %x\n", *p);
}
However, the value you assign to p is neglected since you are using p = &v , the p has the correct address assigned to v by compiler or OS. when you define int v; at run time a memory location is allocated then p will get the address.
in general you are trying to make an integer variable and a pointer to this variable to have two references to the same variable.
In general you don't need to keep track of the address values for variable or pointers when you are using them , you just need to know how to use them properly and when to use them
General Examlpe for pointer usage
#include <stdio.h>
void changeA( int*);
int main() {
int a=1;
printf("%d",a);
changeA(&a);
printf("%d",a);
return 0;
}
void changeA(int* pA){
*pA=2;
}
Output
1 2
the previous example shows the usage of pointers where you can access variables with a different scope , variable a is defined within the scope of main function , and by using the pointers by providing the address of the variable a for the function changeA the function can access the memory location where the variable a is saved in the memory and change it directly from another function scope.
usually pointers used when you need to have multiple outputs for a function and the return can be used to return only one variable. with pointers you will have unlimited capabilities of each function.