Advertisement
cellsheet

pointers example

Feb 17th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int i = 5;
  7.     int *p = &i; /* &i = address of variable i, p = address of i, *p = 5 */
  8.     cout << p << " this is the pointer\n";
  9.     cout << &p << " address of pointer I think\n";
  10.     cout << &i << " address of i\n";
  11.     cout << *p << " Lastly, this is the value (not address part) of the pointer p itself (AKA *p).";
  12.    
  13.     //cout << p = address
  14.     //cout << &i = address
  15.     //cout << *p = number
  16.     //cout << i = number obviously
  17.    
  18.  
  19.     //p by itself just returns the address of int i whereas
  20.     //*p is digging into the address of where the value stored into i lives
  21.     //(its address) and retreives it thus bringing
  22.     //back a number from the address cell.
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement