/***************************************************************************
 *  Columbia University Introduction to Computer Programming in C COMS 1003
 *  Show basic pointer concepts
 *
 *  Copyright (C) 2005 Michael E. Locasto
 *
 *  All rights reserved.
 *
 * $Id: basicpointers.c,v 1.1 2005/11/15 00:49:33 locasto Exp $
 **************************************************************************/

#include <stdio.h>
#include <stdlib.h>

/**
 * A log of what we did in class with pointer concepts. 
 */
int main(int argc, char* argv[])
{
   int x = 0;
   int *x_ptr = NULL;

   x_ptr = x; //should produce a warning!

   printf("sizeof(x) = %d\n",sizeof(x));
   printf("sizeof(x_ptr) = %d\n",sizeof(x_ptr));

   printf("value (contents) of x_ptr = %p\n",x_ptr);
   /* Due to the initialization of x to be zero, this statement will
    * cause a segmentation fault because you are not allowed to
    * access the memory location at address zero.
    */
   //printf("value (contents) of what x_ptr points to = %d\n",*x_ptr);

   x_ptr = &x; //usual and appropriate use of 'addressof' operator

   printf("value (contents) of x_ptr = %p\n",x_ptr);
   printf("value (contents) of what x_ptr points to = %d\n",*x_ptr);

   x = 2; //change the value of the box that x_ptr points to

   printf("value (contents) of x_ptr = %p\n",x_ptr);
   printf("value (contents) of what x_ptr points to = %d\n",*x_ptr);

   exit(0);
}
