Guest User

Untitled

a guest
Dec 14th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. // Using the new operator
  3. using namespace std;
  4.  
  5. int main() {
  6.    
  7.     int nights = 1001;
  8.     int* pt = new int;  // allocate space for an int
  9.     *pt = 1001;         // store a value there
  10.    
  11.     cout << "nights value = ";
  12.     cout << nights << ": location " << &nights << endl;
  13.     cout << "int ";
  14.     cout << "value = " << *pt << ": location = " << pt << endl;
  15.    
  16.     double* pd = new double;    // allocate space for a double
  17.     *pd = 10000001.0;           // store a double there
  18.    
  19.     cout << "double ";
  20.     cout << "value = " << *pd << ": location = " << pd << endl;
  21.     cout << "location of pointer pd: " << & pd << endl;
  22.     cout << "size of pt = " << sizeof(pt);
  23.     cout << ": size of *pt = " << sizeof(*pt) << endl;
  24.     cout << "size of pd = " << sizeof(pd);
  25.     cout << ": size of *pd = " << sizeof(*pd) << endl;
  26.     delete pd;
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment