#include #include /* A short description of the function, if necessary */ int main (int args, char *argv[]) { int *ptr; // here, star means pointer type int a = 5; ptr = &a; // ptr now had the value of the address of a. // Here, star means follow the pointer and access what is // at the end of it. printf( "a is %d and ptr points to %d\n", a, *ptr ); printf( "ptr has the value %p\n", ptr ); printf( "ptr is at address %p on the stack\n", &ptr ); ptr = malloc( sizeof(int) ); *ptr = 6; printf( "a is %d and ptr points to %d\n", a, *ptr ); printf( "ptr has the value %p\n", ptr ); // create a memory leak ptr = &a; ptr = malloc( sizeof(int) ); *ptr = 7; printf( "ptr has the value %p\n", ptr ); free( ptr ); // this time, free the memory first. // so now, the 7's spot is available for more mallocing but the // 6's spot never will be. // this should cause an error, but doesn't :( printf( "a is %d and ptr points to %d\n", a, *ptr ); ptr = malloc( sizeof(int) ); *ptr = 8; printf( "a is %d and ptr points to %d\n", a, *ptr ); printf( "ptr has the value %p\n", ptr ); }