printf("main addr: %p\n", (void *)main);
int a = 1;
printf("stack addr: %p\n", &a);
int *p = (int *)malloc(sizeof(int));
printf("heap addr: %p\n", p);
free(p);
/*
main addr: 0x102257ee4
stack addr: 0x16dbaab24
heap addr: 0x600002c28050
*/
只是一个很简单的区分方法, 实际上还要受制于架构和指令集等情况.