GregLeck

Untitled

Feb 17th, 2022
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.     int* p = new int;
  9.     *p = 3;
  10.     cout << p << endl;
  11.     cout << *p << endl;
  12.  
  13.     // 'delete' eliminates memory leaks if 'p' reinitialized
  14.     delete p;
  15.  
  16.     p = new int(15);
  17.     cout << p << endl;
  18.     cout << *p << endl;
  19.  
  20.     // Eliminate 'dangling pointer'
  21.     p = nullptr;
  22.  
  23.     system("pause");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment