Guest User

Untitled

a guest
Dec 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. /*************************
  10. * declare the variables *
  11. *************************/
  12. int a, b; // int
  13. int e, f; // int
  14. int *c = &e; // int pointer
  15. int *d = &f; // int pointer
  16.  
  17. /*****************
  18. * assign values *
  19. *****************/
  20. a = 5; // set a = 5
  21. b = 10; // set b = 10
  22. *c = 15; // set value pointed to by c = 15
  23. *d = 20; // set value pointed to by d = 20
  24.  
  25. /*************************
  26. * display the variables *
  27. *************************/
  28. cout << "a: " << a << ", b: " << b << endl;
  29. cout << "c: " << c << ", d: " << d << endl;
  30. cout << "c points to: " << *c << endl;
  31. cout << "d points to: " << *d << endl;
  32. cout << endl;
  33.  
  34. /***********************************
  35. * do stuff with the the variables *
  36. ***********************************/
  37. c = &a; // set c = the address of a
  38. d = &b; // set d = the address of b
  39.  
  40. /****************************************
  41. * display the variables after changing *
  42. ****************************************/
  43. cout << "a: " << a << ", b: " << b << endl;
  44. cout << "c: " << c << ", d: " << d << endl;
  45. cout << "c points to: " << *c << endl;
  46. cout << "d points to: " << *d << endl;
  47. cout << endl;
  48.  
  49. /****************************************
  50. * do more stuff with the the variables *
  51. ****************************************/
  52. *c = 25; // set the value pointed to by c (a) = 25
  53. *d = 30; // set the value pointed to by d (b) = 30
  54.  
  55. /*******************************
  56. * display the variables again *
  57. *******************************/
  58. cout << "a: " << a << ", b: " << b << endl;
  59. cout << "c: " << c << ", d: " << d << endl;
  60. cout << "c points to: " << *c << endl;
  61. cout << "d points to: " << *d << endl;
  62. cout << endl;
  63.  
  64. return 0;
  65. }
Add Comment
Please, Sign In to add comment