Advertisement
CybEl

Example Code of * and &

Jul 16th, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. // * is a pointer operator aka a dereference operator
  6. // & is a reference operator aka address of operator
  7. int x;
  8. int *ptr; //this is how to initialize a pointer
  9.  
  10. x = 5;
  11. ptr = &x; //setting ptr to be reference of x
  12.  
  13. std::cout << "Reading ptr value: " << "0x" << ptr << std::endl;
  14. std::cout << "Value of pointer: " << *ptr << std::endl;
  15. std::cout << "Address of pointer: " << "0x" << &ptr << std::endl;
  16.  
  17. system("pause");
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement