/* Program 7.1.3 from C++ Programming Lecture notes  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 30th September 2001    */

/* This program illustrates the use of "NULL". */ 

#include <iostream>
#include <cstdlib>
using namespace std;

typedef int *IntPtrType; 

int main()
{
	IntPtrType ptr_a, ptr_b;	/* LINE 7 */
	
	ptr_a = new int;
	*ptr_a = 4;
	ptr_b = ptr_a;				/* LINE 11 */
		
	cout << *ptr_a << " " << *ptr_b << "\n";
	
	ptr_b = new int;
	*ptr_b = 7;					/* LINE 16 */
	
	cout << *ptr_a << " " << *ptr_b << "\n";

	*ptr_a = *ptr_b;			/* LINE 20 */
		
	cout << *ptr_a << " " << *ptr_b << "\n";
	
	delete ptr_a;
	ptr_a = NULL;
	ptr_b = NULL;
	
	if (ptr_a != NULL)
	{
		*ptr_a = 40;
		cout << "*ptr_a == " << *ptr_a;
	}
	else
	{
		cout << "Dangling pointer error - program terminated\n";
		exit(1);
	}
		
	return 0;
}
