/* some pointer fun and games */ #include int main() { int x, y; /* integer variables */ int *ptr; /* a pointer to an integer variable */ x = 256; /* assigning the variable 'x' the value 256 */ ptr = &x; /* assigning the address of 'x' in memory to the pointer 'ptr' */ y = *ptr; /* ptr is dereferenced to assign the value 256 to y */ printf("x is %d\n", x); /* printing the value of x */ printf("&x is %u\n", &x); /* printing the address of x */ printf("*ptr is %d\n", *ptr); /* printing what ptr points to */ printf("ptr is %u\n", ptr); /* printing the address ptr points to */ printf("y is %d\n", y); /* printing the value of y */ *ptr = 37; /* ptr is dereferenced to obtain an address in order to store 37. In other words, 'store 37 in the memory location pointed to by ptr' */ printf("x is now %d\n", x); printf("&x is now %u\n", &x); printf("*ptr is now %d\n", *ptr); printf("ptr is now %u\n", ptr); printf("y is now %d\n", y); }