I am trying to create a pointer to an address in memory given by the user, but I am having problems. I actually manage to create the pointer and print its address, but I never succeed to print or change its content. Would any one kindly explain why?
Here is the code I'm trying to run:
int m = 10;
printf("&m = %d (address in dec.)\n", &m);
printf("Enter an address: ");
int address;
scanf("%d", &address);
int* p = (int*) address;
printf("p = %d (address in dec.)\n", p);
printf("*p = %d (value)\n", *p);
and here is a console of me interacting with the program:
&m = 1220033252 (address in dec.)
Enter an address: 1220033252
p = 1220033252 (address in dec.)
Segmentation fault
Same thing happens if I try an address different from &m.
Thanks!