Making a pointer point to a specific address?

Started by
3 comments, last by robertgamble 21 years, 5 months ago
How would I make a pointer point to a specific memory address? Say I have an integer "int *i" and when I assign a value to i it updates my memory address.. So instead of:- (int)(*0x5000)=new_value; I can do:- i=new_value; ..to write to 0x5000, Thanks.
Advertisement
To make a pointer point to 0x5000 write this:

int* i = (int*)0x5000;

and now you can write:

*i = new_value;

to change the contents of adress 0x5000;

And thats it.



Jacob Marner, M.Sc.
Console Programmer, Deadline Games
Jacob Marner, M.Sc.Console Programmer, Deadline Games
This sounds like you''re doing something a bit dodgy, but still...
int *pi = reinterpret_cast(0x5000); 
Do both of those cases work?

1. (int)(*0x5000)=new_value;

and

2.int *pi = reinterpret_cast(0x5000);

And could you tell me where the function "reinterpret_cast()"
comes from?

Thanks mates.
"... thats the rub...
hi, reinterpret_cast is a new keyword invented for c++ to get away from the old way of casting. There are four of them,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

This topic is closed to new replies.

Advertisement