fork download
  1. #include <iostream>
  2.  
  3. int t[] = { 1, 2, 3, 4, 5 };
  4.  
  5. int main()
  6. {
  7. int *p = t;
  8.  
  9. std::cout << "t = " << std::hex << t << std::endl; // 0x404010
  10. std::cout << "p = " << std::hex << p << std::endl; // 0x404010
  11. std::cout << "sizeof(t) = " << sizeof(t) << std::endl; // 14 (impl. dependant)
  12. std::cout << "sizeof(p) = " << sizeof(p) << std::endl; // 8 (impl. dependant)
  13. std::cout << "t[2] = " << t[2] << std::endl; // ok: 3
  14. std::cout << "p[2] = " << p[2] << std::endl; // ok: 3
  15.  
  16. ++p; // ok, p can be lvalue
  17. //++t; // syntax error, t cannot be lvalue
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
t = 0x8049bc8
p = 0x8049bc8
sizeof(t) = 14
sizeof(p) = 4
t[2] = 3
p[2] = 3