这是我的程序:
#include <stdio.h>
#include <stdlib.h>
main(){
char *p1, *p2, *p3, *p4;
p1 = (char*)malloc(10);
p2 = (char*)malloc(10);
p3 = (char*)malloc(16);
p4 = (char*)malloc(32);
printf("p1 points at: %d\n", p1);
printf("p2 points at: %d\n", p2);
printf("p3 points at: %d\n", p3);
printf("p4 points at: %d\n\n", p4);
system("PAUSE");
}
在我的电脑上,以下是输出结果:
p1 指向:6492080
p2 指向:6492104
p3 指向:6492128
p4 指向:6492152
所以,无论分配多少字节,每个由malloc分配的内存空间都会往后移动24个字节。为什么会这样呢?感谢您的帮助!