1. ## Pointer to specific memory address

Is it possible to have a pointer point to a SPECIFIC memory address? I want to be able to edit one certain address, and I'm not sure how to go about doing it.

I would've assumed that something similar to

Code:
```int* ptr;
ptr = 0x83fc22;```
but it turns out that this is untrue.

(Background info: I'm using devc++, I am a novice to the concept of pointers, but I am not a novice to programming. I generally program in .NET (vb.net and c#) and Java. )

Do you know how or if this can be done?

Also, another pointer question, while I'm at it: How can I get something's memory address into an int?

As an example, let's say that I want to do something like this
Code:
```int x;
int y;
y = &x; //Obviously, this won't work.  But, I want y to equal
//something like '0x2fecd0'
y += 5;
//so that y can NOW equal 0x2fecd5
cout << "Five more than the memory address of x is  "<< y;```

2. To make this work you can use a cast
Code:
```int* ptr;
ptr = (void *)0x83fc22;```
But this isn't really a good thing to do. You don't know what's at that addres or even if it lies within your address space.

For your second question you can cast to an int

3. > Is it possible to have a pointer point to a SPECIFIC memory address?

Programs operate in virtual memory, so the only memory you have is given to you by the OS. You can't just invent addresses and hope that something useful will happen.

If you're writing device drivers, then obviously you need access to physical resources at some point, but that's pretty heavy stuff.
Likewise, programs like debuggers can inspect and modify the program and data space of the program being debugged, but this is also in "voodoo" territory for most people.

4. Thanks, you two. Quanatum, your solution did the trick. I guess I just wasn't thinking.

Salem, I'll keep that in mind.

5. Originally Posted by elnerdo
Thanks, you two. Quanatum, your solution did the trick. .
That solution only allowed it to compile -- doesn't mean it will work at runtime

6. Just throwin' this in, although you say you've already solved your problem. Back in the day when I did graphics programming, I would use this to get a pointer to the 320x200 (8-bit color) vga screen, which is at 0A0000 in 32-bit protected mode:

Code:
`unsigned char *vga=(unsigned char *)0x0A0000;`

7. answer to your second question, since a pointer is an integer, it is possible to do it like this

Code:
` y=(int)&x;`

8. Originally Posted by RoshanX
since a pointer is an integer, it is possible to do it like this
http://c-faq.com/ptrs/int2ptr.html

9. Originally Posted by RoshanX
answer to your second question, since a pointer is an integer, it is possible to do it like this

Code:
` y=(int)&x;`
won't work when sizeof(int) != sizeof(int *). So your code snippet is non-standard and probably produce unpredictable results with many compilers.

10. > since a pointer is an integer,
Oops - back to school for you.
The standard doesn't even guarantee that all pointers have the same size, never mind being the same size as an int.

11. it is possible and dangerous that a pointer points a SPECIFIC memory address
because may be this address is address of your graphic card or sound card etc... so this fact can spoil your pc (%1 chance )