Jump to content
  • Advertisement

Archived

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

ShadowHunter

memory addressess

This topic is 5460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
quote:
Original post by ShadowHunter
that code only prints out 5, I need the memory address, as in where the variable is located in the memory.
& is the "address of" operator. Saying &a means the "address of a".

This *should* do it:
int a = 5;
std::cout << &a << std::endl;

Share this post


Link to post
Share on other sites

int a = 5;
int *memaddress = &a;

printf("%d\n",memaddress); // prints out memory address


printf("%d\n",*memaddress); // prints out 5



See the difference?

Share this post


Link to post
Share on other sites
quote:
Original post by ShadowHunter
is there anyway to edit something in that memory address, without knowing the variable name?
Yes, but of course you need to get the address initially from someplace (ie. the variable name):
int main()
{
int var = 10;
int *var_ptr = &var; // holds the address of var

std::cout << var << std::endl; // Outputs ''10''

*var_ptr = 5; // Assigns value 5 to the int, pointed to by var_ptr

std::cout << var << std::endl; // Outputs ''5''

return 0;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!