I regret to inform you that only with basic knowledge you will not be able to do this - even with advanced knowledge this is not trivial. You need to somehow enter the process space of the other program, learn or discover how your data structures are defined from memory, know the local and the time exactly where you should read the memory of the program, and map the information read in its concept of "variable".
There are many other considerations. For example, it depends a lot on the environment in which the program is running. Is your program a phone app (iOS / Android / Winphone) or tablets (iOS / Android / Windows)? No chance - the operating system isolates apps so they don’t have access to other applications. Is it a desktop application (Windows or Mac)? Your program would have to have access to the virtual memory space of the other program, which is not the case most of the time (you may need to use one driver (another task for sure non-trivial) to gain access to the memory space of the other process).
Ok, assuming you can at a certain point read the entire memory of the other program (as I said above, it is not a probable hypothesis). What kind of variable do you want to read? If it is a local variable of a method, it will be allocated in the program’s execution stack, then you will have to access the memory exactly at the time that function is running, and know within the stack which value corresponds to the variable you want (another non-trivial task). Another thing: it may be that the variable represents not a primitive value, but an object - which is stored not in the stack, but in the heap of objects (what happens when you use the new
in Java, for example). Then in the stack you will only have the address of the memory space where the value of the variable is. And that value can change - in Java or C#, when the Garbage Collector rotate, the object has chances to be moved.
Anyway, if you want to hack another program, trying to get the value of one of its variables is not the best way :)
If you want to communicate between the two programs, you can use sockets network.
– Avelino