fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <iomanip>
  4. //эта программа призвана дать
  5. // читателю представление о
  6. // расположении переменных в памяти
  7. using namespace std;
  8.  
  9. int main(int intArgc, char* pszArgs[])
  10. {
  11. int m1, n;
  12. long l;
  13. float f;
  14. double d;
  15. int m2;
  16.  
  17. cout<<sizeof(int)<<endl;
  18. cout<<sizeof(long)<<endl;
  19. cout<<sizeof(intptr_t)<<endl;
  20. // Output in 16
  21. cout.setf(ios::hex);
  22. //вывод по очереди чтобы показать размер каждой переменной
  23. cout << " &m1 = 0x" << (uintptr_t)&m1<< endl;
  24. cout << " &n = 0x" << (size_t)&n << endl;
  25. cout << " &1 = 0x" << (size_t)&l << endl;
  26. cout << " &f = 0x" << (size_t)&f << endl;
  27. cout << " &d = 0x" << (size_t)&d << endl;
  28. cout << " &m2 = 0x" << (size_t)&m2<< endl;
  29. return 0;
  30. }
Success #stdin #stdout 0s 4432KB
stdin
Standard input is empty
stdout
4
8
8
 &m1 = 0x140736477114696
 &n  = 0x140736477114700
 &1  = 0x140736477114712
 &f  = 0x140736477114704
 &d  = 0x140736477114720
 &m2 = 0x140736477114708