fork download
  1. #include <iostream>
  2.  
  3. int main ()
  4. {
  5. constexpr int N = 5 ;
  6. int numbers[N] = {0} ;
  7.  
  8. std::cout << N << " elements of array numbers are located at:\n\t" ;
  9. for( int i=0 ; i<N ; ++i ) std::cout << &numbers[i] << ' ' ;
  10. std::cout << '\n' ;
  11.  
  12. int* p = nullptr ;
  13. p = numbers ;
  14. std::cout << "after p = numbers, pointer p points to address: " << p << '\n' ;
  15. *p = 10;
  16.  
  17. ++p ;
  18. std::cout << "after ++p, p points to address: " << p << '\n' ;
  19. *p = 20;
  20.  
  21. p = &numbers[2];
  22. std::cout << "after p = &numbers[2], p points to address: " << p << '\n' ;
  23. *p = 30;
  24.  
  25. p = numbers + 3;
  26. std::cout << "after p = numbers+3, p points to address: " << p << '\n' ;
  27. *p = 40;
  28.  
  29. p = numbers;
  30. std::cout << "after p = numbers, p points to address: " << p << '\n' ;
  31. std::cout << "(p+4) points to address: " << p+4 << '\n' ;
  32. *(p+4) = 50;
  33.  
  34. for( int v : numbers ) std::cout << v << ' ' ;
  35. std::cout << '\n' ;
  36. }
  37.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
5 elements of array numbers are located at:
	0xbfed9e8c 0xbfed9e90 0xbfed9e94 0xbfed9e98 0xbfed9e9c 
after p = numbers, pointer p points to address: 0xbfed9e8c
after ++p, p points to address: 0xbfed9e90
after p = &numbers[2], p points to address: 0xbfed9e94
after p = numbers+3, p points to address: 0xbfed9e98
after p = numbers, p points to address: 0xbfed9e8c
(p+4) points to address: 0xbfed9e9c
10 20 30 40 50