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?.
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.
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?.
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