Pointers in C++

Posted on Updated on

Following my last entry I decided to take another look at C++ pointers, pointer by reference and pointer by value (It’s still confusing for me so I did this to see if it makes telling the two apart any easier):

#include "pointer_test.h"d
#include <iostream>
 
using namespace std;
 
pointer_test::pointer_test() {
  // constructor
}
 
pointer_test::~pointer_test() {
  // destructor
}
 
int main() {
  int var = 20;
  int *ip;    // pointer reference
 
  ip = &var;
 
  cout << "&var -- " << &var << "\n"; // 0x7fff5b73c828, pointer by value
  cout << "var -- " << var << "\n"; // 20, pointer by reference
 
  cout << "&ip -- " << &ip << "\n"; // 0x7fff5b73c828, pointer by value
  cout << "*ip -- " << *ip << "\n"; // 20, pointer by reference
 
  return 0;
}

Also got a haircut on Sunday in Tenjin. First time going to a Japanese salon and I must say for the price I paid (4000-ish yen) I quite like it. At first I would think paying to get a haircut is stupid if I can do it myself but looking this stylish feels refreshing!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s