Archived

This topic is now archived and is closed to further replies.

robertgamble

Making a pointer point to a specific address?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
hi, reinterpret_cast is a new keyword invented for c++ to get away from the old way of casting. There are four of them,

Share this post


Link to post
Share on other sites