Previous      Next

//              Pointers - one level of indirection                                        
//                                                                               
// Declaration: * means "pointer variable"                                     
//     Thus "int *b;" declares b to be a variable of type 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;
   
   b = &a;
   printf("\nAddress of b: %u\n",&b);
   printf("Contents of b: %u\n",b);
   printf("Contents of location pointed to by b: %d\n\n",*b);
   printf("Address of a: %u\n",&a);
   printf("Contents of a: %d\n",a);
}

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