fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int a = 10;
  7. int * p1 = &a;
  8.  
  9. cout<<"value of a: "<<a<<endl;
  10. cout<<"address of a: "<<&a<<endl;
  11.  
  12. cout<<"value of p1: "<<p1<<endl;
  13. cout<<"address of p1: "<<&p1<<endl;
  14. cout<<"value at address stored in p1: "<<*p1<<endl;
  15.  
  16.  
  17. int *p2 = p1;
  18. cout<<"value of p2: "<<p2<<endl;
  19. cout<<"value at address stored in p2: "<<*p2<<endl;
  20.  
  21. int* p3 = new int;
  22. *p3 = 15;
  23. cout<<"value of p3: "<<p3<<endl;
  24. cout<<"value at address stored in p3: "<<*p3<<endl;
  25.  
  26. // delete p3;
  27. // cout<<"value of p3: "<<p3<<endl;
  28. // cout<<"value at address stored in p3: "<<*p3<<endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
value of a: 10
address of a: 0x7ffeb5a1c2dc
value of p1: 0x7ffeb5a1c2dc
address of p1: 0x7ffeb5a1c2e0
value at address stored in p1: 10
value of p2: 0x7ffeb5a1c2dc
value at address stored in p2: 10
value of p3: 0x55f1a2a54e80
value at address stored in p3: 15