これが私のプログラムです:
#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");
}
これにより、PCで次の出力が生成されます。
p1 のポイント: 6492080
p2 ポイント: 6492104
p3 ポイント: 6492128
p4 ポイント: 6492152
そのため、malloc が割り当てる各メモリ空間は、割り当てられたバイト数に関係なく、さらに 24 バイトずつ開始されます。何故ですか?私はあなたの助けに感謝します!