/* some pointer fun and games */ #include int main() { int x, y; /* integer variables */ int *ptr, *ptry; /* 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 */ ptry = &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 */ printf("*ptry is %d\n", *ptry); printf("ptry is %u\n\n", ptry); *ptr = *ptr - 22; 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 */ printf("*ptry is %d\n", *ptry); printf("ptry is %u\n\n", ptry); *ptr = *ptr - 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 */ printf("*ptry is %d\n", *ptry); printf("ptry is %u\n\n", ptry); *ptr = *ptry + x; 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 */ printf("*ptry is %d\n", *ptry); printf("ptry is %u\n\n", ptry); }