memory addressess
that code only prints out 5, I need the memory address, as in where the variable is located in the memory.
quote:Original post by ShadowHunter& is the "address of" operator. Saying &a means the "address of a".
that code only prints out 5, I need the memory address, as in where the variable is located in the memory.
This *should* do it:
int a = 5;std::cout << &a << std::endl;
int a = 5;int *memaddress = &aprintf("%d\n",memaddress); // prints out memory addressprintf("%d\n",*memaddress); // prints out 5
See the difference?
quote:Original post by ShadowHunterYes, but of course you need to get the address initially from someplace (ie. the variable name):
is there anyway to edit something in that memory address, without knowing the variable name?
int main(){ int var = 10; int *var_ptr = &var // holds the address of var std::cout << var << std::endl; // Outputs ''10'' *var_ptr = 5; // Assigns value 5 to the int, pointed to by var_ptr std::cout << var << std::endl; // Outputs ''5'' return 0;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement