fork download
  1. #include <iostream>
  2.  
  3. void dangerous( int const** lhs, int const** rhs )
  4. {
  5. *lhs = *rhs;
  6. }
  7. int main() {
  8. int* pBar = nullptr;
  9. int const foo = 7;
  10. int const* pFoo = &foo;;
  11. dangerous(const_cast<int const**>(&pBar), &pFoo);
  12. std::cout << pBar << "," << pFoo << "\n";
  13. std::cout << *pBar << "," << *pFoo << "\n";
  14. *pBar = 2; // undefined behavior!
  15. std::cout << foo << "," << &foo << "\n";
  16. std::cout << *pBar << "," << pBar << "\n";
  17. // your code goes here
  18. return 0;
  19. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0xbff29dfc,0xbff29dfc
7,7
7,0xbff29dfc
2,0xbff29dfc