Displaying the address of user-entered int should perform as you intend:
int blah;
printf("Address of %d is %d", blah, &blah);
Note the &.
However, you should not be able to do it the other way around. If C or C++ or any language for that matter allowed address control like that, you could crash the entire computer with your program. Here, let me write to protected OS stack memory. A program should never allow "illegal operations" on protected memory, for the sake of the user's computer who is using the machine.
In addition, if you're terminating the first program before starting the second, you have absolutely no idea if that memory address is still valid. What if another program currently running stored something there, temporarily? It was freed up when the first exited. And if you didnt terminate the first before starting the second, then a program has control of that memory access and the OS shouldn't let another program access it.
__________________
"I'm typing on a computer of science, which is being sent by science wires to a little science server where you can access it. I'm not typing on a computer of philosophy or religion or whatever other thing you think can be used to understand the universe because they're a poor substitute in the role of understanding the universe which exists independent from ourselves." - Willravel
|