Thanks for all the replies, Im new to C++ so sorry if the question didnt
make complete sense I was watching a tutorial the other night which
prompted this thought as if a physical address was already in use and
somethiong tried to access it that could easily crash a system right? So
why would C++ allow that be coded? Has to be a reason.
As other people have said, anything could happen. Essentially, if each
program thinks that what is stored is what it put there, then each can
get a nasty surprise when the other one stores something completely
different there.
As to why this should be allowed... Well, firstly, for most ways of
reserving memory C++ will find you a memory location that isn't
already in use. You have to do something special to get the situation
you describe. C++ is based on C, and C tends to assume that the user
knows what they are doing and so will do what they ask for.
One time whem you might use this is if you want to get more than one
value returned from a function. For example, if you want to get a
point, you might have:
void getpoint(int *x, int *y, int *z) {
*x = ...
*y = ...
*z = ...
return;
}
This will allow the function to write into memory locations that are
already in use. For example:
int ax, bx, cx;
getpoint(&ax, &bx, &cx);
which will set the variable ax to the required x value.
There are of course other ways of doing this, one being to return a
struct and one (in C++ but not C) being to use references.
Hope this helps.
Paul.