I am a beginner at C++. The "&" operator means "address of" and so hence my pathetic attempt.
I am still not understanding the code.
using namespace std;
int value = 23;
int* pValue = &value;
cout << *pValue;
Which line of the code above do you not understand?
Please explain further with the memory address: 00B12318
What is special to you about memory address 00B12318? The only time you want to manipulate an exact memory address is either you're developing for some hardware device (a driver), or you're trying to hack something at that address.
@hoxsiew: As the title says, I am trying to READ the value contained in a memory address, in this case it would be "00B12318". I would rather not reveal what I am trying to accomplish.
@GCDEF: int* pInt = "0x00B12318";
int nInt = *pInt; is not working for me either. (error C2440: 'initializing' : cannot convert from 'const char ' to 'int *), of course if I remove the quotes around 0x00B12318 then there would be another error. (cannot convert from 'int' to 'int *')
@Paul: I do not get what the 23 is.
NOTE: 00B12318 is a String (series of letters)
Thanks for all the help guys but it does not solve my problem.
Last edited by Poopynoob; October 27th, 2009 at 02:54 PM.
Alright, I am doing this for a school project. Trying to get a good mark. :P (Although it is not nessesary, nevertheless I might need it later in programming)
@Paul: It gives this error: error C2440: '=' : cannot convert from 'int' to 'int *' when I use the code : int *value;
value = 0x00B12318;
cout << *value; // *value is the data at that address
Simply, in your line:
00B12318 = &value;
the 00B12318 is not an l-value, so your line will cause a syntax error.
To do it properly you should use the way suggested by jnmacd (I will use more suggestive variable names):
int* PointerToInt; // declare a pointer to a memory area used to store an integer
PointerToInt = 0x00B12318; // assign the address 0x00B12318 to that pointer
cout << *PointerToInt; // Show the content of the memory address pointed by PointerToInt
Important to know:
If you access memory addresses allocated to your application, that code will work. If you attempt to access memory addresses from the memory space allocated to other applications, the code will fail.
Normally, an application is denied access to the memory used by other applications. There are three reasons for that. The first is to protect the memory of an application from being spoiled by other applications. The second is the security, to prevent one application to spy on another. The third is easy memory management.
There are some special techniques to access the memory allocated to another application, (like dll injection) but frankly, at the level of your knowledge, at this time , you should focus your attention on understanding more basic tasks.
My guess is that you attempt to hack something, that's why you don't want to talk about your intentions. To me it sounds ok, trying that is an excellent way to learn programming. But be aware that the ideas you're trying to use are far from being new. Usually serious programmers will use sophisticated techniques to protect their software, so you will encounter many nasty suprises. Don't expect that you'll find what you're looking for just from readind the memory.
Alright, I am doing this for a school project. Trying to get a good mark. :P
I would be very surprised to find out that a technique commonly used for cheating at games would be assigned as a school project. Would you care to name the school and the instructor? I would be happy to write to him/her and explain why this is not a proper assignment for someone just learning to program.