なんとなく heap と stack くらいは加えておきました。何か調べたわけでもないので適当。
#include <stdio.h> #include <stdlib.h> #include <unistd.h> extern char __executable_start; extern char etext; extern char __bss_start; extern char end; void print_where(void *p) { printf("%p: ", p); if (&__executable_start > p) { printf("i guess it's not pointer\n"); } else if (&etext > p) { printf("it's in .text\n"); } else if (&__bss_start > p) { printf("i guess it's data\n"); } else if (&end > p) { printf("it's in .bss\n"); } else if (sbrk(0) > p) { printf("it's heap\n"); } else if (p > &p) { printf("it's stack\n"); } else { printf("i guess it's ...\n"); } } int global_variable; int main(int argc, char *argv[]) { static int static_variable; print_where(&main); print_where(&print_where); print_where(&global_variable); print_where(&static_variable); print_where(&argc); print_where(malloc(1)); print_where("hello"); print_where(NULL); return 0; }