Advertisement
obernardovieira

Changing value in memory address

Oct 29th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.         int intvar = 5;
  5.         printf("address of intvar = %p\n", (void *)(&intvar));
  6.         printf("address of intvar - 1 = %p\n", (void *)(&intvar - 1));
  7.         printf("address of intvar + 1 = %p\n", (void *)(&intvar + 1));
  8.  
  9.         uintptr_t z = uintptr_t(&intvar);
  10.         unsigned short *addr = (unsigned short *)z;
  11.         *addr = 100;
  12.  
  13.         uintptr_t p = uintptr_t(&intvar);
  14.         int value = *reinterpret_cast<int *>(p);
  15.  
  16.         printf("value of address = %d\n", value);
  17.  
  18.         system("pause");
  19.         return 1;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement