Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int askUserFn();
  4. int displayPtr(int& n);
  5.  
  6. int main()
  7. {
  8. int x = askUserFn();
  9. int y = askUserFn();
  10. // int *ptrX = &x;
  11. // int *ptrY = &y;
  12. displayPtr(x);
  13. displayPtr(y);
  14.  
  15. }
  16.  
  17. int askUserFn()
  18. {
  19. std::cout << "Enter a number: ";
  20. int x;
  21. std::cin >> x;
  22. return x;
  23. }
  24.  
  25. int displayPtr(int& n)
  26. {
  27. int *ptrN = &n;
  28. std::cout << "The pointer has value " << *ptrN << " and is stored in address " << ptrN << std::endl;
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement