/* * Memory on the stack and on the heap. * * Jed Yang */ #include #include int main(void) { int a; // on the stack printf("stack address: &a = %p\n", &a); int *b; b = malloc(sizeof(int)); // allocate on the heap if (!b) { printf("oops, out of memory\n"); return 1; // convention to signal something is wrong } printf("heap address: b = %p\n", b); printf("stack address: &b = %p\n", &b); free(b); // always free() what you malloc() return 0; // convention to signal correct termination }