#!/usr/bin/env /friends/bin/cscript #include #include #include struct bar { int x; int y; }; void show_ptr(const char *varname, void *ptr, const char *desc) { printf("%8s = %0.12p (%s)\n", varname, ptr, desc); } int foo0; int foo1 = 123; struct bar bar0 = {.x = 0, .y = 0}; void foo(void) { int foo2; int foo3 = 100; struct bar bar1; struct bar *bar2 = malloc(sizeof(struct bar)); show_ptr("&foo0", &foo0, "data"); show_ptr("&foo1", &foo1, "data"); show_ptr("&foo2", &foo2, "stack"); show_ptr("&foo3", &foo3, "stack"); show_ptr("&bar0", &bar0, "data"); show_ptr("&bar1", &bar1, "stack"); show_ptr("bar2", bar2, "heap"); } int main(int argc, char **argv) { printf("\n"); foo(); return 0; }