fork(1) download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. #define print_address(x) ( std::cout << "address of " #x " is " << std::addressof(x) \
  5.   << " (" << std::uintptr_t( std::addressof(x) ) << ")\n" )
  6.  
  7. void foo()
  8. {
  9. int foo_a = 0 ;
  10. static int foo_b = 1 ;
  11. int foo_c[5] = { 2, 3, 4, 5, 6 } ;
  12. print_address(foo_a) ;
  13. print_address(foo_b) ;
  14. print_address( foo_c[0] ) ;
  15. print_address( foo_c[1] ) ;
  16. }
  17.  
  18. void bar()
  19. {
  20. int bar_a = 0 ;
  21. static int bar_b = 1 ;
  22. static int bar_c[5] = { 2, 3, 4, 5, 6 } ;
  23. print_address(bar_a) ;
  24. print_address(bar_b) ;
  25. print_address( bar_c[0] ) ;
  26. print_address( bar_c[1] ) ;
  27.  
  28. std::cout << "--------------------------\n" ;
  29.  
  30. foo() ;
  31. }
  32.  
  33. int main ()
  34. {
  35. int main_a = 0 ;
  36. static int main_b = 1 ;
  37. int main_c[5] = { 2, 3, 4, 5, 6 } ;
  38. print_address(main_a) ;
  39. print_address(main_b) ;
  40. print_address( main_c[0] ) ;
  41. print_address( main_c[1] ) ;
  42.  
  43. std::cout << "--------------------------\n" ;
  44.  
  45. foo() ;
  46.  
  47. std::cout << "--------------------------\n" ;
  48.  
  49. bar() ;
  50. }
  51.  
Success #stdin #stdout 0s 2900KB
stdin
Standard input is empty
stdout
address of main_a is 0xbfcd9148 (3217920328)
address of main_b is 0x804a240 (134521408)
address of main_c[0] is 0xbfcd914c (3217920332)
address of main_c[1] is 0xbfcd9150 (3217920336)
--------------------------
address of foo_a is 0xbfcd9108 (3217920264)
address of foo_b is 0x804a224 (134521380)
address of foo_c[0] is 0xbfcd910c (3217920268)
address of foo_c[1] is 0xbfcd9110 (3217920272)
--------------------------
address of bar_a is 0xbfcd911c (3217920284)
address of bar_b is 0x804a228 (134521384)
address of bar_c[0] is 0x804a22c (134521388)
address of bar_c[1] is 0x804a230 (134521392)
--------------------------
address of foo_a is 0xbfcd90d8 (3217920216)
address of foo_b is 0x804a224 (134521380)
address of foo_c[0] is 0xbfcd90dc (3217920220)
address of foo_c[1] is 0xbfcd90e0 (3217920224)