Puzzle P9

a and b pointed to by pa, pt, and pb

What does the following code write to the monitor?

#include <stdio.h>
int main( void )
{
  int  a = 44 ;
  int  b = 66 ;
  int *pa, *pb, *pt ;
  
  pa = &a ; 
  pb = &b ; 
  printf("*pa=%d *pb=%d\n", *pa, *pb );
  
  /* Swap pointer values */
  pt = pa;
  pa = pb;
  pb = pt;
 
  printf("*pa=%d *pb=%d\n", *pa, *pb );

  return 0;
}

The dotted lines in the diagram show the situation at the time of the first printf(). The solid lines show the final situation.



Previous Page        Answer         Next Page         Home