fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. using namespace std;
  4.  
  5. int main() {
  6. const int N = 5;
  7. int A[N][5];
  8.  
  9. int i = 1, j = 1;
  10.  
  11. auto a = &A[i][j];
  12. auto b = A+i*N+j;
  13.  
  14. if (!std::is_same<decltype(a), decltype(b)>::value)
  15. {
  16. std::cout << "The pointers are not of the same type.\n";
  17. }
  18.  
  19. if (static_cast<void*>(a) != static_cast<void*>(b))
  20. {
  21. std::cout << "The pointers do not have the same value.\n";
  22. }
  23. }
  24.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
The pointers are not of the same type.
The pointers do not have the same value.