Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  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. *dPtr = 34.6;
  22. *iPtr = 21;
  23. cout << "Changed value of i1 by dereferencing: " << i1DReferenced << endl;
  24. cout << "Changed value of d1 by dereferencing: " << d1DReferenced << endl;
  25.  
  26.  
  27. cout << "i1 Directly: " << i1 << endl;
  28. cout << "d1 Directly: " << d1 << endl;
  29. cout << "i2 directly: " << i2 << endl;
  30. cout << "d2 directly: " << d2 << endl;
  31.  
  32. iPtr = &i2;
  33. dPtr = &d2;
  34. cout << "Address of i2: " << iPtr << endl;
  35. cout << "Address of d2: " << dPtr << endl;
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. system("pause");
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement