/* demoPassByRef.c  P. Conrad 11/01/04 CISC105 */

#include <stdio.h>

int squared (int x)
{
  printf("x before=%d\n",x);
  return (x * x);
}


void squareIt(int *p)
{
  printf("p before=%p, *p before=%d\n", p, *p);
  
  (*p) = (*p) * (*p);

  printf("p after=%p, *p after=%d\n", p, *p);

}

int main(void)

{

  int a=7;
  int b=3;

  printf("squared(4)=%d\n",squared(4));
  printf("squared(a+1)=%d\n",squared(a+1));
  printf("squared(a)=%d\n",squared(a));
  
  printf("&a=%p\n", &a);

#if (0)
  printf("squareIt(4)=%d\n",squareIt(4)); /* this makes an error */
  printf("squareIt(a+1)=%d\n",squareIt(a+1)); /* error */
  printf("squareIt(a)=%d\n",squareIt(a)); /* error */
#endif

  printf("value of b before call to squareIt(&b)=%d \n",b);
  printf("value of &b before call to squareIt(&b)=%p \n",&b);
  squareIt(&b);

  printf("value of b after call to squareIt(&b)=%d \n",b);
  printf("value of &b after call to squareIt(&b)=%p \n",&b);

  return 0;
}

