// ==========================================================================
// $Id: auto_ref.cpp,v 1.2 2016/09/19 18:11:24 jlang Exp $
// CSI2372 example Code for lecture 3
// ==========================================================================
// (C)opyright:
//
//   Jochen Lang
//   SITE, University of Ottawa
//   800 King Edward Ave.
//   Ottawa, On., K1N 6N5
//   Canada. 
//   http://www.site.uottawa.ca
// 
// Creator: jlang (Jochen Lang)
// Email:   jlang@site.uottawa.ca
// ==========================================================================
// $Log: auto_ref.cpp,v $
// Revision 1.2  2016/09/19 18:11:24  jlang
// Aligned auto and decltype examples
//
// Revision 1.1  2014/09/13 19:48:03  jlang
// Added C++11 features to lecture 3
//
//
// ==========================================================================
#include <iostream>

using std::cout;
using std::endl;

int main( ) {
  int i=3, &iRef = i, *iPtr = &i;
  cout << "i = " << i << "\t";
  cout << "iRef = " << iRef << "\t";
  cout << "*iPtr = " << *iPtr << endl;
	
  auto iVal = iRef;
  ++i;
  cout << "iVal = " << iVal << " but ";
  cout << "iRef = " << iRef << endl;
  --i;
  // Instead explicitly define as reference
  auto &jRef = i;
  ++i;
  cout << "i = " << i << " and ";
  cout << "jRef = " << jRef << " (reference)" << endl;
  
  // No auto without initialization
  auto kPtr = iPtr;
  cout << "kPtr = " << kPtr << " (pointer)" << endl;
	
  auto &lPtr = iPtr;
  iPtr = &iVal;
  cout << "i = " << i << endl;
  cout << "iPtr = " << iPtr << "  *iPtr = " << *iPtr << " and ";
  cout << "lPtr = " << lPtr << " *lPtr = " << *lPtr; 
  cout << " (reference to pointer)" << endl;

  return 0;
}
