Puzzle P23


Puzzle P23 — Three Levels of Indirection

As you might fear, you can have pointers to pointers to pointers. Here is an example of that:

#include  <stdio.h> 

void main ( void )
{
  int value;
  int *pv;
  int **ppv;
  int ***pppv;

  value = 32;
  pv = &value;
  ppv = &pv;
  pppv = &ppv;
  
  printf("value = %d\n", value );
  printf("*pv   = %d\n", *pv );
  printf("*(*ppv) = %d\n", *(*ppv) );
  printf("*(*(*pppv)) = %d\n", *(*(*pppv)) );

  system("pause");
}

There is rarely a reason to have more than three levels of indirection (pointer to pointer to pointer to something), although C allows it.

What does this program write to the monitor?



Previous Page        Answer         Next Page         Home