So there are two parts to this, and I'll do my best.
When compiling, a compiler will convert the C++ code into an internal representation. This is then converted into using the CPU's registers as efficiently as possible, and pushing the rest of the data into RAM. As the program executes, data from ram will get copied back and forth into registers.
On your other question, one method I've seen that people use for this is for the gold that a user has. A program could take the entire memory space of the game and copy it. Then, the user does something (a minimal action) to gain or lose gold. The external application then searches through the entire memory space for what values have changed, and what previously was the original amount of gold, and what is now the current amount of gold. Once they find this location, they are able to edit the memory location and update it with whatever value they want.
Generally, the more complicated the game is, the harder that method is.