int a = 0; // 全局初始化區 (.data)
char *p1; // 全局未初始化區 (.bss)
main() {
int b; // 棧
char s[]="abc"; // 棟
char *p2; // 棧
char *p3="123456";// 字符串常量區(.rodata),p3在棧
static int c=0; // 全局/靜態初始化區
p1 = malloc(10); // 堆
p2 = malloc(20); // 堆
}
char *p1="helloworld";
char *p2="helloworld";
char p3[]="helloworld";
char p4[]="helloworld";
printf("%p %p %p %p", p1, p2, p3, p4);
// 輸出:p1==p2 (常量區去重),p3!=p4 (棧上獨立副本)
指針指向同一常量區地址,數組各自在棧複製內容。