Advertisement
bhok

Pointers start

Jul 3rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. // More code tutorials at brandonhok.com
  4. // pointers and how they work
  5.  
  6. int main()
  7. {
  8.     int hotdog = 4;
  9.     int* hotdogPoint = &hotdog;
  10.     int* corndogPoint;
  11.     corndogPoint = &hotdog;
  12.    
  13.     // main value
  14.     std::cout << hotdog;
  15.  
  16.     // prints addresses because of &
  17.     std::cout << std::endl << hotdogPoint
  18.         << std::endl << corndogPoint << std::endl;
  19.    
  20.     // prints value of address because of *
  21.     std::cout << *hotdogPoint << std::endl;
  22.     std::cout << *corndogPoint << std::endl;
  23.    
  24.     // when used together, they are addresses
  25.     std::cout << *&hotdogPoint << std::endl << &*hotdogPoint;
  26.     system("pause");
  27.  
  28.     // try creating your own pointers and using different values
  29.     // can you develop a hamburger pointer that uses a larger number?
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement