View Single Post
Old 10-08-2006, 03:10 PM   #2 (permalink)
Jinn
Lover - Protector - Teacher
 
Jinn's Avatar
 
Join Date: May 2005
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.
__________________
If you struggle with something your entire life, try harder.
Awareness without action is worthless, and failure is not an accident.
Jinn is offline   Reply With Quote