fork download
  1. #include <iostream>
  2. #include <stdint.h>
  3.  
  4. void a()
  5. {
  6. uint32_t i = 42;
  7.  
  8. uint8_t * c = reinterpret_cast<uint8_t*>(&i);
  9. c[0] = 0;
  10. c[1] = 0;
  11. c[2] = 0;
  12. c[3] = 0;
  13.  
  14. std::cout << "i = " << i << std::endl;
  15. }
  16.  
  17. void b()
  18. {
  19. uint32_t i = 42;
  20.  
  21. uint16_t * s = reinterpret_cast<uint16_t*>(&i);
  22. s[0] = 0;
  23. s[1] = 0;
  24.  
  25. std::cout << "i = " << i << std::endl;
  26. }
  27.  
  28. int main()
  29. {
  30. a();
  31. b();
  32. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
i = 0
i = 42