#include <iostream>
int main()
{
int i = 0;
return 0;
}
How would I chage the variable i into 2 during runtime without having the source code/knowledge of the variable even existed? Or is that even possible in this example?
1) disassemble your program, replace needed part with jump, do your manipulations and jump back.
2) Pause your process, find address of your variable and write anything you want in it.
3) your concrete example is un"hack"able because your assigment is simply optimized away.
The optimizer runs at compile time, not run time.
And yes, if the optimizer determines that the pointer is not used, it would also be removed by the optimizer.