求教变量分配位置
#include <stdio.h>#include <stdlib.h>
char *str3;
int main(void)
{
char *str1 = "hello world";
char str2[] = "hello world two";
str3 = "hello world three";
char *str4 = malloc(sizeof(char)*1024);
if (str4 == NULL)
return -1;
str4 = "hello world four";
printf("%x %s\n", &str1, str1);
printf("%x %s\n", &str2, str2);
printf("%x %s\n", &str3, str3);
printf("%x %s\n", &str4, str4);
return 0;
}
widon@widon-F3JR:/tmp$ ./a.out
bfe60164 hello world
bfe6016c hello world two
804a024 hello world three
bfe60168 hello world four
str1,str2都在栈空间分配,str3在静态存取区域,str4在堆吧,
可是str1,str2,str4分配地址是连续的啊