proffreda

C++ Introduction to Pointers

Feb 17th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.  int x = -99;
  6.  cout << "Size of x: " << sizeof(x) << endl;
  7.  cout << "Address of x: " <<  &(x)  << endl;
  8.  cout << "Size of Address of x: " <<  sizeof(&x)  << endl;
  9.  cout << "Value pointed to by Address of x: " <<  *(&(x))  << endl;
  10.  cout << "Size of value pointed to by Address of x: " <<  sizeof(*&x)  << endl;
  11.  cout << endl;
  12.  cout << "Pointer Variables" << endl;
  13.  int* xptr = &x;
  14.  cout << "Size of xptr: " << sizeof(xptr) << endl;
  15.  cout << "Value pointed to by xptr: " << *xptr << endl;
  16.  cout << "Address of xptr: " <<  &(xptr)  << endl;
  17.  cout << "Size of Address of xptr: " <<  sizeof(&xptr)  << endl;
  18.  cout << "Value pointed to by Address of xptr: " <<  *(&(xptr))  << endl;
  19.  cout << "Size of value pointed to by Address of xptr: " <<  sizeof(*&xptr)  << endl;
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment