Alex Rivera | Logout

How to initialize a pointer to a specific memory address in C++

Asked 2010-10-14T15:22:51.260
13

An interesting discussion about this started here but no one have been able to provide the C++ way of doing:

#include <stdio.h>

int main(void)
{
  int* address = (int *)0x604769; 
  printf("Memory address is: 0x%p\n", address);

  *address = 0xdead; 
  printf("Content of the address is: 0x%p\n", *address);

  return 0;
}

What is the most appropriate way of doing such a thing in C++?

Edit
Report

1 Answer

1

This will work:

void *address=(void *) 0xdead; // But as mentioned, it's non-standard

address=(void *) 0xdeadbeef; // Some other address
answered 2010-10-14T15:26:02.780

Your Answer