#include int main() { int x, y; int *ptr1, *ptr2; x = 7; y = 8; printf("x and y are %d and %d \n", x, y); ptr1 = &x; printf("x and its location are %d and %p \n", x, ptr1); ptr2 = &y; printf("y and its location are %d and %p \n\n", y, ptr2); printf("Two ways to print the value in x are demonstrated: \n"); printf(" One way by using just x: %d \n", x); printf(" Other way by using *ptr1: %d \n", *ptr1); /* Assign to y the value at location pointed by ptr1. Therefore, y changes */ y = *ptr1; printf("y and its location are %d and %p \n\n", y, ptr2); /* Change ptr1 so that it points to the same location as ptr2 */ ptr1 = ptr2; /* update x */ x =10; /* Since ptr1 no longer points to x, but points to y, the value *ptr1 does not change after assigning 10 to x. Now both pointers are identical and point to the same value of y */ printf(" ptr1= %p\n ptr2= %p\n value at ptr1=%d and value at ptr2=%d\n",ptr1,ptr2,*ptr1,*ptr2); return(0); } /* I got the following output, but on your computer it will be different becauses addresses &x and &y will be different in memory of your computer. Moreover, if you run this program repeatedly, you will get different memory addresses because when your operating system loads your program, it allocates each time a new memory segment to program variables. x and y are 7 and 8 x and its location are 7 and 0x7fff46c9fd5c y and its location are 8 and 0x7fff46c9fd58 Two ways to print the value in x are demonstrated: One way by using just x: 7 Other way by using *ptr1: 7 y and its location are 7 and 0x7fff46c9fd58 ptr1= 0x7fff46c9fd58 ptr2= 0x7fff46c9fd58 value at ptr1=7 and value at ptr2=7 */