SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int i1 = 5;
  7.     int i2 = 500;
  8.     double d1 = 1.234;
  9.     double d2 = 100.456;
  10.     cout << "First integer = " << i1 << endl;
  11.     cout << "First double = " << d1 << endl;
  12.  
  13.     int *iPtr = &i1;
  14.     double *dPtr = &d1;
  15.     cout << "address of first pointer = " << iPtr << " and address of second pointer = " << dPtr << endl;
  16.  
  17.  
  18.     int i1DReferenced = *iPtr;
  19.     double d1DReferenced = *dPtr;
  20.     cout << "Dereferenced pointer of i1: " << i1DReferenced << " and dereferenced pointer of d1: " << d1DReferenced << endl;
  21.  
  22.  
  23.     double d3 = *dPtr;
  24.     *dPtr = 17.7;
  25.     int i3 = *iPtr;
  26.     *iPtr = 3;
  27.     cout << "Changed value of i1 by dereferencing: " << i1 << endl;
  28.     cout << "Changed value of d1 by dereferencing: " << d1 << endl;
  29.  
  30.  
  31.     cout << "i1 Directly: " << i3 << endl;
  32.     cout << "d1 Directly: " << d3 << endl << endl;;
  33.     cout << "i2 directly: " << i2 << endl;
  34.     cout << "d2 directly: " << d2 << endl;
  35.  
  36.     iPtr = &i2;
  37.     dPtr = &d2;
  38.     cout << "Address of i2: " << iPtr << endl;
  39.     cout << "Address of d2: " << dPtr << endl;
  40.  
  41.      
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.     system("pause");
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top