Getting the value of the particular memory address

Dear All,
I am a new one for this forum.I have a memory address like 0x0012FF7C.
I want to read the value of this address.Is it possible?.If yes means how can i
do this?.

Thanks in advance
First cast it to something, then dereference it. For example. *(int *)0x0012FF7C.
Note that if the memory address is not legally accessible by the program, this will cause a segmentation fault. It may be possible to read it regardless with a system call, though I'm not sure.
Thanks for ur reply.
I am not getting the answer.Here i have attached my code.please see that one.

#include "stdafx.h"
#include <iostream.h>
#include <stdlib.h>

void main()
{
char *p1 = "pps";
char **p = &p1;
cout<<p<<endl;
cout<<*p<<endl;
}

o/p:

0x0012FF7C
pps


In the above code is working fine.But I should pass only memory address.So i have changed my code like,

#include "stdafx.h"
#include <iostream.h>
#include <stdlib.h>

void main()
{
//char *p1 = "pps";
char **p = (char**)0x0012FF7C;
cout<<p<<endl;
cout<<*p<<endl;
}


o/p:

0x0012FF7C
| ↕

If i take the comment line from first line i got the answer.But i should pass only memory address only.we dont know what type of values are available in that memory?.

If u know send the code..please...

In the first example, you get 0x0012FF7C, which is the address of the pointer p1, but this value is incidental. There's no guarantee that the next time the program executes that address will even be accessible to the program.

"pps" is a string statically allocated in the program. This means that a portion of the executable is set aside and contains an array with the values {'p','p','s',0}. When the program executes and the executable is loaded to memory, p1 is set to point to the first character. If you comment that line, the array is never allocated in the program.
Dereferencing p is very dangerous, since you have no guarantee that whatever happens to be at 0x0012FF7C is a valid pointer.

You're really playing with fire with that code of yours. If you tell me what exactly it is you're trying to do I can give you some advice.
You say you want to read the value of an address like 0x0012FF7C ....that is the value.
Do you mean you want to convert the integer format from hex to dec?
If so just set the hec and dec flags so:
1
2
3
4
int num;
cout<<"Enter an integer in hex format";
cin>>hex>>num;
cout<<num<<"in dec format is"<<dec<<num;//prints 1245052 


hth's
Topic archived. No new replies allowed.