Previous      Next

//             Pointers - two levels of indirection                                        
//                                                                               
// Declaration: * means "pointer variable"                                     
//     Thus "int *b;" declares b to be a variable of type pointer to int       
//     "int **c;" declares c to be a variable of type pointer to pointer to int
// Non-declaration: * means contents of, & means address of                      
//     Thus "*b = 10;" means the int location pointed to by b gets value 10    
//     "b = &a;" means the contents of b is set to the address of variable a

void main()
{
   int a=10;
   int *b;
   int **c;
   
   b = &a;
   c = &b;
   printf("\nAddress of a: %u\n",&a);
   printf("Address of b: %u\n",&b);
   printf("Address of c: %u\n\n",&c);
   printf("Contents of c: %u\n",c);
   printf("Contents of location pointed to by c: %u\n",*c);
   printf("Contents of location pointed to by location pointed to by c: %d\n",**c);
}

// Sample Output:
//   Address of a: 3221223444
//   Address of b: 3221223440
//   Address of c: 3221223436
//
//   Contents of c: 3221223440
//   Contents of location pointed to by c: 3221223444
//   Contents of location pointed to by location pointed to by c: 10