// experi6a.c

#include <malloc.h>
#include <conio.h>
#include <stdio.h>
#include <bios.h>

void main(void)
{
  int x,y,*ptr1,*ptr2;

  // cause ptr1 to point to the memory location of x
  ptr1 = &x;

  // notice that x is being set equal to 5 AFTER ptr1 is made to point to x
  x = 5;

  // the * dereferences ptr1, which is to say it provides the value pointed to
  printf("ptr1 points to x's address: x = %d *prt1 = %d\n",x,*ptr1);

  y = 10;
  ptr2 = &y;

  printf("ptr2 points to y's address: y = %d *prt2 = %d\n",y,*ptr2);

  ptr2 = &x;

  printf("both ptr1 and ptr2 point to x's address: x = %d y = %d *prt1 = %d *prt2 = %d\n"
  ,x,y,*ptr1,*ptr2);

  *ptr2 = 123;

  printf("dereferenced ptr2 changed to 123: x = %d y = %d *prt1 = %d *prt2 = %d\n"
  ,x,y,*ptr1,*ptr2);

} // end experi6a.c

