fork(4) download
  1. #include <iostream>
  2. #include <cstdint>
  3. #include <sstream>
  4.  
  5. int main()
  6. {
  7. int i = 1234567 ;
  8. const int* p = &i ;
  9.  
  10. std::string address ;
  11. {
  12. std::ostringstream ostm ;
  13. ostm << reinterpret_cast<std::uintptr_t>(p) ;
  14. address = ostm.str() ;
  15. }
  16.  
  17. std::uintptr_t n ;
  18. {
  19. std::istringstream istm(address) ;
  20. istm >> n ;
  21. }
  22.  
  23. const int* q = reinterpret_cast<const int*>(n) ;
  24.  
  25. std::cout << "the int at address " << p << " is " << *p << '\n'
  26. << "the int at address " << q << " is " << *q << '\n' ;
  27. }
  28.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
the int at address 0xbf92aed4 is 1234567
the int at address 0xbf92aed4 is 1234567